The javadoc for StandardWatchEventKinds.ENTRY_MODIFY says:
Directory entry modified. When a directory is registered for this event the
I compiled Oracle's WatchDir.java and @nilesh's suggestion into an Observable class that will notify it's observers once when the watched file is changed.
I tried to make it as readable and short as possible, but still landed with more than 100 lines. Improvements welcome, of course.
Usage:
FileChangeNotifier fileReloader = new FileChangeNotifier(File file);
fileReloader.addObserver((Observable obj, Object arg) -> {
System.out.println("File changed for the " + arg + " time.");
});
See my solution on GitHub: FileChangeNotifier.java.