What is the most efficient way to detect modification to a file in Java?
I've read about file polling however, the polling approach has a number of drawbacks that become apparent as the number of watched files increases. I rather not use polling but a number of solutions online appear to point to file polling as the recommended method. I was hoping for perhaps an OS-related file system update callback solution instead -- is this possible in both linux and windows?
Given that I currently only intend to 'watch' 2 files, I'm still kind of open to a file polling solution. Ideally, I'm hoping file polling won't have a great impact on performance.
I'm aware of Java 7's WatchService but since 7 hasn't been officially released, I'm hesitant to use that approach or JNI libraries.
Much appreciated!
EDIT: It appear file polling is the way to go. If anyone can recommend the most safest/efficient way to implement file polling, that would be great.