Watching a Directory for Modifications in Java 7

NIO 2.0 in Java 7 added support for directory change notification known as a watch service. It lets you receive notifications, when a directory is modified. There are six steps needed to set up a watch service.

  • Creating a watch service
  • Registering a directory with the watch service
  • Retrieving a watch key from the watch service queue
  • Processing the events that occurred on the registered directory
  • Resetting the watch key after processing the events
  • Closing the watch service

A watch service is an instance of the WatchService interface. You can create a watch service for the default file system as:

WatchService ws = FileSystems.getDefault().newWatchService();

Click here to read the full post in PDF format.

 

 

Downloads


2 Comments on “Watching a Directory for Modifications in Java 7”

  1. sheikh azar says:

    Please write some books on Servlet,JSP,Web Services and on MVC pattern..
    It will be wonderful if you write fully on JAVA web technology.

    I have benefited extensively from your three series books on Java.You are really man of your own word, what you have said in your Preface it holds true and been proved…

    Great insights you have..

    Hope to see following JAVA EDITIONS on Web Technology.


Leave a Reply

Your email address will not be published. Required fields are marked *