With Java we can Use the WatchService to detect the kind of events have occurred in a specific file or even directory.
The Implementation is easy as You can just get WatchService from FileSystem as follow:
1- Get the WatchService: WatchService watchService = FileSystems.getDefault().newWatchService();
2- Use the WatchService in Your file:
FILE_LOCATION.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_CREATE)
After all, You can see all kind of events that had occurred in Your file like above: StandardWatchEventKinds.ENTRY_MODIFY which mean that your file has been modified.
For more details check the link below:
https://github.com/PascoalBayonne/Exercise/blob/master/src/nio/directory/watching/DirectoryWatching.java