title: How to show only one message for File Change Event Java
body: <p>When the file structure changes. I keep getting <code>println</code>s for every single file that was changed. How do I make it so that I only get one <code>println</code> for <strong>multiple changes</strong> in a 10 second period?</p>
  
  <pre><code>try {
      WatchService watchService = FileSystems.getDefault().newWatchService();
      Path path = new File("C:\\Users\\myuser\\Desktop\\TestFolder").toPath();
  
      path.register(
          watchService,
          StandardWatchEventKinds.ENTRY_CREATE,
          StandardWatchEventKinds.ENTRY_DELETE,
          StandardWatchEventKinds.ENTRY_MODIFY);
  
      WatchKey key;
  
      while ((key = watchService.take()) != null) {
          for (WatchEvent&lt;?&gt; event : key.pollEvents()) {
  
              System.out.println(
                  "Event kind:" + event.kind() + ". File affected: " + event.context() + ".");
              System.out.println("Something changed!");
              Thread.sleep(10000);
              System.out.println("Resuming..");
              break;
          }
          key.reset();
      }
  } catch (IOException e) {
      e.printStackTrace();
  } catch (InterruptedException e) {
      e.printStackTrace();
  }
  </code></pre>