When an object in the file system is modified, we can listen watch to the service to get an alert. The java.nio.file following classes and interfaces in the package provide watch services.
Watchableobject represents a file system object that can be monitored. Watchableobjects can be watch registered with the service.
PathObject is an Watchable object.
WatchServiceRepresents the observation service. When an object uses WatchService registration, it WatchService returns a WatchKey token that is registered. WatchEventrepresents an event on an object that is registered to the monitoring service. Its kind() method returns the type of event that occurred.
Its context() method returns an Path object that represents the entry in which the event occurred. count()method returns the number of times an event occurred for a specific notification. If it returns a value greater than 1 , then it is a repeating event.
WatchEvent.Kind <T>Represents the type of event that occurred. StandardWatchEventKindsclass defines the constants used to represent the kind of event, as shown below.
Click on the link to view the details
Java Directory Events