0

WatchService を使用して、複数のファイルへの変更がないかディレクトリをスキャンしようとしています。変更された特定のディレクトリ内の正確なテキスト ファイルを特定できます。プログラムに変更内容を正確に表示させ、その変更を特定の変数で検索する方法があるかどうか疑問に思っています。

新しいエントリは次のようになります

07/02/15 11:44、88、55

この線を引いて、88 または 55 が 100 以上になるかどうかをスキャンします。

これが私の現在のコードです。

public void scanChanges() {
    Path p = Paths.get("C:\\Users\\achamberlain\\Desktop\\Data");
    try {
        WatchService watcher = p.getFileSystem().newWatchService();
        p.register(watcher, ENTRY_CREATE, ENTRY_MODIFY);

        for (;;) {
            WatchKey key = null;
            key= watcher.take();

            for (WatchEvent<?> event : key.pollEvents()) {
                String location;
                location = (p + "\\" + event.context().toString());
                Watcher sendlocation = new Watcher();
                sendlocation.readFile(location);
                key.reset();
            }
        }
    } catch (IOException | InterruptedException e) {
    }
}

public class Watcher {

    public static void main(String[] args) throws IOException {
        Modify modClass = new Modify();
        modClass.scanChanges();   
    }

    //changes "location" to "fileName" for use in this class
    public void readFile(String fileName){
        System.out.println(fileName);
    }
}
4

0 に答える 0