Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you sure there is problem with jdk7? It gives correct result for me (jdk7u15, windows)</p> <p>Code</p> <pre><code>import java.io.IOException; import java.nio.file.*; public class WatchTest { public void watchMyFiles() throws IOException, InterruptedException { Path path = Paths.get("c:/temp"); WatchService watchService = path.getFileSystem().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); while (true) { WatchKey watchKey = watchService.take(); // blocks for (WatchEvent&lt;?&gt; event : watchKey.pollEvents()) { WatchEvent&lt;Path&gt; watchEvent = (WatchEvent&lt;Path&gt;) event; WatchEvent.Kind&lt;Path&gt; kind = watchEvent.kind(); System.out.println(watchEvent.context() + ", count: " + watchEvent.count() + ", event: " + watchEvent.kind()); // prints (loop on the while twice) // servers.cfg, count: 1, event: ENTRY_MODIFY // servers.cfg, count: 1, event: ENTRY_MODIFY switch (kind.name()) { case "ENTRY_MODIFY": handleModify(watchEvent.context()); // reload configuration class break; case "ENTRY_DELETE": handleDelete(watchEvent.context()); // do something else break; default: System.out.println("Event not expected " + event.kind().name()); } } watchKey.reset(); } } private void handleDelete(Path context) { System.out.println("handleDelete " + context.getFileName()); } private void handleModify(Path context) { System.out.println("handleModify " + context.getFileName()); } public static void main(String[] args) throws IOException, InterruptedException { new WatchTest().watchMyFiles(); } } </code></pre> <p>Output is like below- when file is copied over or edited using notepad. </p> <pre><code>config.xml, count: 1, event: ENTRY_MODIFY handleModify config.xml </code></pre> <p>Vi uses many additional files, and seems to update file attribute multiple times. notepad++ does exactly two times.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload