I am using watch service first time, I am trying to update a file using watch service but it's updating that file two times.
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 I also getting an another error, when i want to create same file again just after deleting first file. then i am getting below error
java.io.FileNotFoundException: D:\Watson\docs\FMO-OMS_Requirements.docx (The process cannot access the file because it is being used by another process)