public class PathsDemo { public static void main(String[] args){ try { //The first step is to create a new WatchService by using the newWatchService method in the FileSystem class. WatchService watchService=FileSystems.getDefault().newWatchService(); //register one or more objects with the watch service. //When registering an object with the watch service, you specify the types of events that you want to monitor. Paths.get(propertiesPath).register(watchService, StandardWatchEventKinds.ENTRY_CREATE, //A directory entry is created StandardWatchEventKinds.ENTRY_DELETE, //A directory entry is deleted StandardWatchEventKinds.ENTRY_MODIFY);//A directory entry is modified. while(true) { //Returns a queued key. If no queued key is available, this method waits. WatchKey key=watchService.take(); for(WatchEvent<?> event:key.pollEvents()) { System.out.println(event.context()+" happens "+event.kind()+" event."); //TODO business operations... } if(!key.reset()) { break; } } } catch (Exception e) { System.err.println(e); } } }