jfilewatcher Wiki
Brought to you by:
mohdejaz
Here's how you use it from command line ...
java -jar jfilewatcher-2.0.jar /home /projects
Here's how you use it programmatically ...
:::java
JFileWatcherService fservice = new JFileWatcherService();
// If you want to watch specific files,
// pass second arg as an array of Strings of regexp patterns
fservice.watch(new File(args[0]), null);
// Start file watcher service (it is a thread!)
fservice.start();
// Wait for the file event (NEW, MODIFIED, DELETE)
SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy HH:mm a");
while (true) {
JFileWatcherEvent e = fservice.next();
System.out.println(
"[" + fmt.format(e.getFile().lastModified()) + "] "
+ e.getType()
+ " : "
+ e.getFile().getAbsolutePath());
}