Answers for "watch service does not detect more than one poll java"

1

watch service does not detect more than one poll java

Path pathBattlesFolder = Paths.get("filepath");
WatchService watchService = pathBattlesFolder.getFileSystem().newWatchService();
pathBattlesFolder.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
WatchKey watchKey = null;
while(true){

  watchKey = watchService.poll();
  if (watchKey != null){
    if (watchKey.pollEvents().size() > 0){
      //if it gets here then something has been changed
    }
    watchKey.reset();
  }

}

**watchKey.reset() should fix the problem.
Posted by: Guest on June-18-2021

Code answers related to "watch service does not detect more than one poll java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language