I would like to know how to efficiently implement filesystem changes in java? Say I got a file in a folder and modify that file. I would like to be notified by java about this change as soon as possible(no frequently polling if possible.).
Because I think I could call java.io.file.lastModified every few seconds but I don't like the sound of that solution at all.
alfred@alfred-laptop:~/testje$ java -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Server VM (build 16.0-b13, mixed mode)
Take a look at JNotify, which performs this type of monitoring.
Java 7 will have some more advanced APIs (WatchService) for this sort of work which will eliminate polling on the OSes that support this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With