I need to know when a new file appears in a directory. Obviously, I could poll the file system periodically, but that has all the normal downsides of polling mechanisms.
I know that windows supports file system events, and this project is already constrained to the Windows platform by other requirements.
Does anyone have experience receiving Windows filesystem events inside a JVM? If so what are the best practices, patterns, and/or libraries you have used?
A quick google turns up this library. Does anyone have experience with it (or any other) that they'd be willing to share?
I think this is one of the key features of Java 7 when it is more available. Example code from Sun's blog on Java 7:
import static java.nio.file.StandardWatchEventKind.*;
Path dir = ...;
try {
WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
} catch (IOException x) {
System.err.println(x);
}
For Java 6 or older use JNA's com.sun.jna.platform.win32.FileMonitor.
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