apache vfs 监视文件变化
琴乐音 2010-01-25 09:42:07 有谁用过这个监视文件, 他是用轮寻的方式实现的, 我用他监视文件, 代码:
FileSystemManager fsManager = null;
FileObject listendir = null;
try {
fsManager = VFS.getManager();
listendir = fsManager.resolveFile(new File("c:/test/1.txt")
.getAbsolutePath());
} catch (FileSystemException e) {
logger.error("监视文件夹出错了", e);
e.printStackTrace();
}
String watchDir = listendir.toString().substring(8);
System.out.println("watch path: " + watchDir);
this.fm = new DefaultFileMonitor(new FileListener() {
public void fileCreated(FileChangeEvent event) throws Exception {
System.out.println("创建文件");
}
public void fileDeleted(FileChangeEvent event) throws Exception {
System.out.println("删除文件");
}
public void fileChanged(FileChangeEvent event) throws Exception {
System.out.println("修改文件");
}
当我创建文件,删除文件或改变文件时, 相对应的方法会执行3次, 为什么呢? 我想只执行一次就行了?