Menu

Home

Mohammed Ejaz

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());
}

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.
Try Free →