feat(mon_dir): registered Path instance for modification events using WatchService instance
This commit is contained in:
parent
a22078bc17
commit
ab0f3328f3
|
@ -13,8 +13,9 @@ public class Main {
|
||||||
//obtain WatchService instance using FileSystems class
|
//obtain WatchService instance using FileSystems class
|
||||||
WatchService watchService = FileSystems.getDefault().newWatchService();
|
WatchService watchService = FileSystems.getDefault().newWatchService();
|
||||||
|
|
||||||
//register path to be watched with this instance
|
//register a Path instance for events using a WatchService instance
|
||||||
folder.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
|
folder.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
|
||||||
|
StandardWatchEventKinds.ENTRY_MODIFY);
|
||||||
|
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
do {
|
do {
|
||||||
|
@ -25,7 +26,7 @@ public class Main {
|
||||||
|
|
||||||
if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
|
if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
|
||||||
String fileName = event.context().toString();
|
String fileName = event.context().toString();
|
||||||
System.out.println("File Created:" + fileName);
|
System.out.println("File created:" + fileName);
|
||||||
} else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(event.kind())) {
|
} else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(event.kind())) {
|
||||||
String fileName = event.context().toString();
|
String fileName = event.context().toString();
|
||||||
System.out.println("File modified:" + fileName);
|
System.out.println("File modified:" + fileName);
|
||||||
|
|
Loading…
Reference in New Issue