我第一次使用监视服务,我正在尝试使用监视服务更新文件,但它会更新该文件两次。
boolean valid = true;
do{
WatchKey watchKey = watchService.take();
for(WatchEvent<?> event : watchKey.pollEvents()){
WatchEvent.Kind kind = event.kind();
if(StandardWatchEventKinds.ENTRY_CREATE.equals(kind)){
String fileName = event.context().toString();
}
if(StandardWatchEventKinds.ENTRY_MODIFY.equals(kind)){
String fileName = event.context().toString();
}
if(StandardWatchEventKinds.ENTRY_DELETE.equals(kind)){
String fileName = event.context().toString();
}
}
valid = watchKey.reset();
}while(valid);
Somtime我还得到另一个错误,当我想在删除第一个文件后再次创建相同的文件。然后我得到低于错误
java.io.FileNotFoundException: D:\Watson\docs\FMO-OMS_Requirements.docx (The process cannot access the file because it is being used by another process)