Skip to content

Instantly share code, notes, and snippets.

@alcides
Created September 21, 2011 09:47
Show Gist options
  • Save alcides/1231686 to your computer and use it in GitHub Desktop.
Save alcides/1231686 to your computer and use it in GitHub Desktop.
public class JNotifyExample
public static void main(String[] args) throws InterruptedException, IOException
{
String dir = new File(args.length == 0 ? "." : args[0]).getCanonicalFile().getAbsolutePath();
JNotify.addWatch(dir, FILE_ANY, true, new JNotifyListener()
{
public void fileRenamed(int wd, String rootPath, String oldName,
String newName)
{
System.out.println("renamed " + rootPath + " : " + oldName + " -> " + newName);
}
public void fileModified(int wd, String rootPath, String name)
{
System.out.println("modified " + rootPath + " : " + name);
}
public void fileDeleted(int wd, String rootPath, String name)
{
System.out.println("deleted " + rootPath + " : " + name);
}
public void fileCreated(int wd, String rootPath, String name)
{
System.out.println("created " + rootPath + " : " + name);
}
});
System.err.println("Monitoring " + dir + ", ctrl+c to stop");
while (true) Thread.sleep(10000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment