java - How can I check that folder is tracked by WatchService? -


if start watching changes in folder a, delete , recreate watchservice not trigger events folder. wanna rewatch folder a after forgotten watchservice.

how can check folder a still tracked watchservice?

there no need monitor parent folder, there way know if watcher have no longer works can recreate it.

the following code should out.

watchservice watchservice = null; string folderstring = "your path here";  {     thread.sleep(1000);     file dir = new file(folderstring);      if (!dir.exists())         continue;      watchservice = filesystems.getdefault().newwatchservice();      path folder = paths.get(folderstring);      folder.register(watchservice,         standardwatcheventkinds.entry_create,         standardwatcheventkinds.entry_delete,         standardwatcheventkinds.entry_modify);      boolean watchstilloperational = false;          {         watchkey watchkey = watchservice.take();          (watchevent<?> event : watchkey.pollevents())         {             .....         }          // following line indicates if watch no longer works         // if folder deleted return false.         watchstilloperational = watchkey.reset();      } while (watchstilloperational)  } while(true) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -