The javadoc for StandardWatchEventKinds.ENTRY_MODIFY
says:
Directory entry modified. When a directory is registered for this event the
If you are trying the same in Scala using better-files-akka
library, I have comeup with this work around based on the solution proposed in the accepted answer.
https://github.com/pathikrit/better-files/issues/313
trait ConfWatcher {
implicit def actorSystem: ActorSystem
private val confPath = "/home/codingkapoor/application.conf"
private val appConfFile = File(confPath)
private var appConfLastModified = appConfFile.lastModifiedTime
val watcher: ActorRef = appConfFile.newWatcher(recursive = false)
watcher ! on(EventType.ENTRY_MODIFY) { file =>
if (appConfLastModified.compareTo(file.lastModifiedTime) < 0) {
// TODO
appConfLastModified = file.lastModifiedTime
}
}
}
I had a similar issue - I am using the WatchService API to keep directories in sync, but observed that in many cases, updates were being performed twice. I seem to have resolved the issue by checking the timestamp on the files - this seems to screen out the second copy operation. (At least in windows 7 - I can't be sure if it will work correctly in other operation systems)
Maybe you could use something similar? Store the timestamp from the file and reload only when the timestamp is updated?