在java中,如何看多个目录
答
这是一个名为File Monitor的组件,它位于apache commonsIO库中。我想这只是你要找的。
+0
是的..有没有任何示例代码。 – ssbecse 2011-05-21 08:56:03
答
请试试这个,
for(;;){
System.out.println("START MONITORING **************");
Path faxFolder = Paths.get("E:\\activiti\\monitor\\m1");
Path faxFolder2 = Paths.get("E:\\activiti\\monitor\\m2");
WatchService watchService = FileSystems.getDefault().newWatchService();
faxFolder.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
faxFolder2.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
boolean valid = true;
WatchKey watchKey = watchService.take();
for (WatchEvent<?> event : watchKey.pollEvents()) {
WatchEvent.Kind kind = event.kind();
if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
String fileName = event.context().toString();
System.out.println(fileName);
}
}
}
http://stackoverflow.com/questions/1096404/is-there-a-sophisticated-file-system-monitor-for-java-which-is-的重复freeware-or-open -s和http://stackoverflow.com/questions/3810790/is-it-possible-to-monitor-folder-using-java-code – 2011-05-21 08:50:38