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

Method main

files/PathWatcher.java:30–50  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

28 }
29 }
30 public static void
31 main(String[] args) throws Exception {
32 Directories.refreshTestDir();
33 Directories.populateTestDir();
34 Files.createFile(test.resolve("Hello.txt"));
35 WatchService watcher =
36 FileSystems.getDefault().newWatchService();
37 test.register(watcher, ENTRY_DELETE);
38 Executors.newSingleThreadScheduledExecutor()
39 .schedule(
40 PathWatcher::delTxtFiles,
41 250, TimeUnit.MILLISECONDS);
42 WatchKey key = watcher.take();
43 for(WatchEvent evt : key.pollEvents()) {
44 System.out.println(
45 "evt.context(): " + evt.context() +
46 "\nevt.count(): " + evt.count() +
47 "\nevt.kind(): " + evt.kind());
48 System.exit(0);
49 }
50 }
51}
52/* Output:
53deleting test\bag\foo\bar\baz\File.txt

Callers

nothing calls this directly

Calls 3

refreshTestDirMethod · 0.95
populateTestDirMethod · 0.95
countMethod · 0.45

Tested by

no test coverage detected