watch service java

Solutions on MaxInterview for watch service java by the best coders in the world

showing results for - "watch service java"
Kelyan
16 Jul 2017
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}