Friday 5 August 2016

Folder Watcher using java.nio.file.WatcherService

A simple folder inspector/watcher which logs the user action into a file.
User actions includes :
- Create
- Modify
- Delete

Here we are going to discuss on few new classes introduced as part of java.nio package with Java 1.7
- java.nio.file.Path : This represents typically represent a system dependent file path to locate a file in a file system.
- java.nio.file.WatchService : It a service that watches registered objects for changes and events. For example a file manager may use a watch service to monitor a directory for changes so that it can update its display of the list of files when files are created or deleted.
- java.nio.file.WatchEvent : An event for an object that is registered with a WatchService.
- java.nio.file.WatchKey : A token representing the registration of a watchable object with a WatchService. Here Path is a watchable object which will be watched by WatchService.
- java.nio.file.FileSystems : Factory methods for file systems.
- java.nio.file.FileSystem : It is an interface to a file system and is the factory for objects to access files and other objects in the file system.

FolderWatcher.java

Output:dir-log.txt


No comments:

Post a Comment