A WatchService
only watches the Path
s you register. It does not go through those paths recursively.
Given /Root
as a registered path
/Root
/Folder1
/Folder2
/Folder3
If there is a change in Folder3
, it won't catch it.
You can register the directory paths recursively yourself with
private void registerRecursive(final Path root) throws IOException {
// register all subfolders
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
return FileVisitResult.CONTINUE;
}
});
}
Now the WatchService
will notify all changes in all subfolders of Path root
, ie. the Path
argument you pass.