Wednesday, August 17, 2011

Reacting To File System Events with Java 7

File system events occurs whenever a file or directory are created or modified in Windows or any other operating systems. Java 7 introduces new API called WatchService in the java.nio.file package for monitoring file system events. To test, I created a very short program in NetBeans IDE 7.0.1 called rondroid.coin.io.FileSystemWatcher (I name it after C# System.IO.FileSystemWatcher). Below is my 51 liner code - FileSystemWatcher.java.


The program is very short and it does a very simple thing:

  • Ask the default file system to create a new WatchService instance.
  • Watch the specific path for create and delete file system event;
  • And when the file system event occur notify all the subscribed rondroid.coin.io.FileNotificationListener.

See also:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.