Here you can find the source of registerRecursive(final WatchService watcher, final List
public static void registerRecursive(final WatchService watcher, final List<Path> startingPaths) throws IOException
//package com.java2s; //License from project: Apache License import com.sun.nio.file.SensitivityWatchEventModifier; import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.List; public class Main { /**//from w ww .j av a 2 s .co m * Register the given directory, and all its sub-directories, with the WatchService. * Populates the given 'keys' map with WatchKeys -> Paths. */ public static void registerRecursive(final WatchService watcher, final List<Path> startingPaths) throws IOException { for (Path start : startingPaths) { // register directory and sub-directories Files.walkFileTree(start, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { register(watcher, dir); return FileVisitResult.CONTINUE; } }); } } /** * Register the given directory with the WatchService */ public static void register(final WatchService watcher, final Path dir) throws IOException { dir.register( watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE }, SensitivityWatchEventModifier.HIGH); } }