public static void main(String[] args) throws Exception { final FileSystem fileSystem = FileSystems.getDefault(); try (final WatchService watchService = fileSystem.newWatchService()) { final Map<WatchKey, Path> keyMap = new HashMap<WatchKey, Path>(); final Path path = Paths.get("F:\\Test"); keyMap.put(path.register(watchService, ENTRY_CREATE, ENTRY_DELETE),path); WatchKey watchKey; do { watchKey = watchService.take(); final Path eventDir = keyMap.get(watchKey); for (final WatchEvent<?> event : watchKey.pollEvents()) { final WatchEvent.Kind kind = event.kind(); final Path eventPath = (Path) event.context(); System.out.println(eventDir + ": " + event.kind() + ": " + event.context()); } } while (watchKey.reset()); } }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------ jnotify 详见 http://www.blogjava.net/pengo/archive/2011/01/09/342622.html jnotify分为64位 和 32位。 详见 http://jnotify.sourceforge.net/ public class Test {