Configuring JNotify on Windows
I am using Java JNotify to listen for directories events.
However, w开发者_StackOverflow中文版henever i'm running the program below, the program is terminating immediately with no error nothing
Instead, i think the program should wait for events
import net.contentobjects.jnotify.*;
public class ListenFile
{
public static void main(String [] args) throws JNotifyException
{
String path = "C:/Users/noor/Desktop/Files";
int mask = JNotify.FILE_CREATED |
JNotify.FILE_DELETED |
JNotify.FILE_MODIFIED|
JNotify.FILE_RENAMED;
boolean watchSubtree = true;
int watchID = JNotify.addWatch(path, mask, watchSubtree, new JNotifyListener(){
@Override
public void fileCreated(int arg0, String arg1, String arg2) {
System.out.println("1");
}
@Override
public void fileDeleted(int arg0, String arg1, String arg2) {
// TODO Auto-generated method stub
System.out.println("2");
}
@Override
public void fileModified(int arg0, String arg1, String arg2) {
// TODO Auto-generated method stub
System.out.println("3");
}
@Override
public void fileRenamed(int arg0, String arg1, String arg2,
String arg3) {
// TODO Auto-generated method stub
System.out.println("4");
}});
try
{
Thread.sleep(1000000);
}
catch (InterruptedException e1)
{
}
}
}
Your program needs to enter a while (true) {};
loop or some other loop after the catch
clause that will not let the application terminate.
精彩评论