MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / watchDir

Method watchDir

files/TreeWatcher.java:12–34  ·  view source on GitHub ↗
(Path dir)

Source from the content-addressed store, hash-verified

10
11public class TreeWatcher {
12 static void watchDir(Path dir) {
13 try {
14 WatchService watcher =
15 FileSystems.getDefault().newWatchService();
16 dir.register(watcher, ENTRY_DELETE);
17 Executors.newSingleThreadExecutor().submit(() -> {
18 try {
19 WatchKey key = watcher.take();
20 for(WatchEvent evt : key.pollEvents()) {
21 System.out.println(
22 "evt.context(): " + evt.context() +
23 "\nevt.count(): " + evt.count() +
24 "\nevt.kind(): " + evt.kind());
25 System.exit(0);
26 }
27 } catch(InterruptedException e) {
28 return;
29 }
30 });
31 } catch(IOException e) {
32 throw new RuntimeException(e);
33 }
34 }
35 public static void
36 main(String[] args) throws Exception {
37 Directories.refreshTestDir();

Callers

nothing calls this directly

Calls 1

countMethod · 0.45

Tested by

no test coverage detected