| 10 | |
| 11 | public 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(); |