[英]Want to define state-sequence of processes in the property file in Java
我計划構建一個繼續查找目錄的程序,如果有新文件出現,它將通知我。 但是我不想使用Watch Service API。 還有其他簡單的邏輯可以做到嗎? 不使用任何第三方API或庫?
Watch Service API是執行此操作的最簡單,最有效的方法,這就是它存在的原因。
但是,您可以輪詢目錄並查找更改。 這有一些缺點。
還有其他簡單的邏輯可以做到嗎?
反復打電話
File dir = new File(directoryName);
// note: creates a lot of garbage even if nothing changed.
File[] files = dir.listFiles();
if (files != null) {
// check for changes.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.