原来可以这样用java来监控文件,
private static void nio() throws IOException { WatchService watcher = null; try { try { watcher = FileSystems.getDefault().newWatchService(); String path = "D:\\test\\as";// 要监控的文件或者目录 Paths.get(path).register(watcher, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE); } catch (IOException e) { e.printStackTrace(); throw e; } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } while (true) { WatchKey key = null; try { key = watcher.take(); } catch (InterruptedException e) { continue; } for (WatchEvent<?> event : key.pollEvents()) { WatchEvent.Kind<?> kind = event.kind(); if (kind == StandardWatchEventKinds.OVERFLOW) { continue; } if (kind == StandardWatchEventKinds.ENTRY_MODIFY || kind == StandardWatchEventKinds.ENTRY_CREATE || kind == StandardWatchEventKinds.ENTRY_DELETE) { System.out.println("AAAAAAAASSS");// 处理特定事件! break; } } key.reset(); } }