あなたがFileAlterationListenerを使用してFileAlterationListenerAdaptorを追加する場合は、あなたが必要なメソッドを実装し、FileAlterationMonito
public static void main(String[] args) throws Exception {
FileAlterationObserver fao = new FileAlterationObserver(dir);
final long interval = 500;
FileAlterationMonitor monitor = new FileAlterationMonitor(interval);
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
@Override
public void onFileCreate(File file) {
try {
System.out.println("File created: " + file.getCanonicalPath());
} catch(IOException e) {
e.printStackTrace(System.err);
}
}
@Override
public void onFileDelete(File file) {
try {
System.out.println("File removed: " + file.getCanonicalPath());
} catch(IOException e) {
e.printStackTrace(System.err);
}
}
@Override
public void onFileChange(File file) {
try {
System.out.println(file.getName() + " changed: ");
} catch(Exception e) {
e.printStackTrace();
}
}
};
// Add listeners...
fao.addListener(listener);
monitor.addObserver(fao);
monitor.start();
}
でファイルを監視することができます[私が尋ねることができますどのような話題]お読みください(http://stackoverflow.com/help/on-topic)と[良い質問をする方法](http://stackoverflow.com/help/how-to-ask)と[完璧な質問](https://codeblog.jonskeet.uk/ 2010/08/29/writing-the-perfect-question /)と[最小限の完全かつ検証可能なサンプルの作成方法](http://stackoverflow.com/help/mcve)を参照してください。 SOは無料のコーディング、コード変換、デバッグ、チュートリアル、ライブラリ検索サービスではありません。あなたのコードを修正しようとします。コードは書きません。 – java4fun