Reputation: 8191
I am trying to build a fileSystemWatcher in java (similar to FileSystemWatcher in C#). Please suggest whether java has any built in framework capability for this or suggest/direct to any sample/open source projects.
Upvotes: 8
Views: 6691
Reputation: 15778
Check out the Apache Commons JCI FAM (FileAlterationMonitor). The unit tests should give you an idea how to use it.
Upvotes: 7
Reputation: 147124
"More NIO Features" in JDK7 should have a cross-platform version of such a facility (taking advantage of particular platform capabilities on any reasonable JRE implementation).
Upvotes: 4
Reputation: 272217
I don't believe there's any inbuilt capability. You can always poll the directory in a thread, and watch for directory modification times etc. That's trivial, but I'm not sure how OSes differ in how they'll reflect directory changes in the directory meta data. If you have to keep track of a directory with a large number of files, any solutions based on polling may be quite heavyweight.
I note this, which is a more optimal version for Windows (not that I know what platform you're on!)
Upvotes: 0