1Path path = Paths.get(".");
2WatchService watchService = path.getFileSystem().newWatchService();
3path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
4
5WatchKey watchKey = null;
6while (true) {
7 watchKey = watchService.poll(10, TimeUnit.MINUTES);
8 if(watchKey != null) {
9 watchKey.pollEvents().stream().forEach(event -> System.out.println(event.context()));
10 }
11 watchKey.reset();
12}