2010-07-01 27 views
1

傳入的文件我想打一個Java程序,持續監控目錄的新文件,過程在一個目錄

,如果一個新的文件到達,過程,然後將其刪除。

這樣做的最好方法是什麼?

回答

3

檢查新文件,對它們進行處理,沖洗,重複:

while (true) { 
    File[] files = new File(DIRECTORY_PATH).listFiles(); 
    for (File file : files) { 
     /* do something with this file */ 

     //and delete it when finished 
     file.delete(); 
    } 

    //Pause for a second before checking again 
    Thread.sleep(1000); 
}