title: Monitor subfolders with a Java watch service
body: <p>I am using <code>watchKey</code> to listen for a file change in a particular folder.</p>
  
  <pre><code>Path _directotyToWatch = Paths.get("E:/Raja");
  WatchService watcherSvc = FileSystems.getDefault().newWatchService();
  WatchKey watchKey = _directotyToWatch.register(watcherSvc, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
  
  while (true) {
      watchKey=watcherSvc.take();
      for (WatchEvent&lt;?&gt; event: watchKey.pollEvents()) {
          WatchEvent&lt;Path&gt; watchEvent = castEvent(event);
          System.out.println(event.kind().name().toString() + " " + _directotyToWatch.resolve(watchEvent.context()));
          watchKey.reset();
      }
  }
  </code></pre>
  
  <p><br />
  It working fine for me. If I modify a file in raja folder it gives me the file name with path. But, when I put some files in subfolders like "E:/Raja/Test", it gives me only the path where I put it, not the file name.</p>
  
  <p>How to get the file name?</p>