-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (22 loc) · 908 Bytes
/
Copy pathMain.java
File metadata and controls
30 lines (22 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String directory = System.getProperty("user.dir") + "/java7/watch-service/src/";
System.out.println("Browse to " + directory + " and try creating/modifying/deleting files...");
WatchService watchService = FileSystems.getDefault().newWatchService();
Path watchPath = Paths.get(directory);
watchPath.register(
watchService,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
WatchKey watchKey = watchService.take();
boolean poll = true;
while (poll) {
for (WatchEvent<?> event : watchKey.pollEvents()) {
System.out.println("Event kind: " + event.kind() + " for file: " + event.context());
}
poll = watchKey.reset();
}
}
}