Java examples for File Path IO:File System
The supported types of events are defined in the StandardWatchEventKinds.
The following code snippet registers the Path with the watch service with the monitored events: create, delete, and modify.
import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchService; public class Main { public static void main(String[] args) throws Exception { final Path path = Paths.get("C:/folder1"); WatchService watchService = FileSystems.getDefault().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); watchService.close();/*from w w w .ja va2s .com*/ } }