You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LiveDirsFX is a combination of a directory watcher, a directory-tree model (for TreeView) and a simple asynchronous file I/O facility. The extra benefits of this combination are:
Automatic synchronization of the directory model with the filesystem.
Ability to distinguish directory and file modifications made by the application (through the I/O facility) from external modifications.
Example
enumChangeSource {
INTERNAL, // indicates a change made by this applicationEXTERNAL, // indicates an external change
}
// create LiveDirs to watch a directoryLiveDirs<ChangeSource> liveDirs = newLiveDirs<>(EXTERNAL);
Pathdir = Paths.get("/path/to/watched/directory/");
liveDirs.addTopLevelDirectory(dir);
// use LiveDirs as a TreeView modelTreeView<Path> treeView = newTreeView<>(liveDirs.model().getRoot());
treeView.setShowRoot(false);
// handle external changesliveDirs.model().modifications().subscribe(m -> {
if(m.getInitiator() == EXTERNAL) {
// handle external modification, e.g. reload the modified filereload(m.getPath());
} else {
// modification done by this application, no extra action needed
}
});
// Use LiveDirs's I/O facility to write to the filesystem,// in order to be able to distinguish between internal and external changes.Pathfile = dir.resolve("some/file.txt");
liveDirs.io().saveUTF8File(file, "Hello text file!", INTERNAL);
// clean upliveDirs.dispose();
Use LiveDirsFX in your project
Method 1: as a managed dependency (recommended)
Snapshot releases are deployed to Sonatype snapshot repository with these Maven coordinates