nio监控文件变化
简介 nio主要是通过WatchService、Watchkey和Path来实现文件的监控; 代码实现 public class FileMonitor { private WatchService watcher; public FileMonitor(String directory) throws IOException { watcher = FileSystems.getDefault().newWatchService(); Path path = Paths.get(directory); path.register(watcher, ENTRY_CREATE, ENTRY_MODIFY,ENTRY_DELETE); } @SuppressWarnings("InfiniteLoopStatement") public void watchFile() throws InterruptedException{ while (true) { WatchKey key = watcher.take(); for (WatchEvent<?> event : key....