Reputation: 168
I want to listen to execution of files in my computer from a java application. And I need the details of those files. How to listen to file execution event?
Upvotes: 0
Views: 125
Reputation: 41230
Right from documentation -
Java 7 introduced Java WatchService
.
A watch 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. A Watchable object is registered with a watch service by invoking its register method, returning a WatchKey to represent the registration. When an event for an object is detected the key is signalled, and if not currently signalled, it is queued to the watch service so that it can be retrieved by consumers that invoke the poll or take methods to retrieve keys and process events. Once the events have been processed the consumer invokes the key's reset method to reset the key which allows the key to be signalled and re-queued with further events.
Upvotes: 1