code: private void registerDirectory(Path dir) throws IOException {
          Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
  
              @Override
              public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                  WatchKey key = dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
                  watchKeyToDirectory.put(key, dir);
  
                  return FileVisitResult.CONTINUE;
              }
  
          });
      }
docs: Register the given directory, and all its sub-directories.