Monitor folder and print new files6/25/2023 ![]() ![]() You can choose to handle the overflow or ignore it, but you should test for it. No matter what events the key has registered for, it is possible to receive an OVERFLOW event. Retrieve the type of event by using the.Process the pending events for the key.If no queued key is available, this method waits. The TimeUnit argument determines whether the specified time is nanoseconds, milliseconds, or some other unit of time. If a queued key is not immediately available, the program waits until the specified time. poll(long, TimeUnit) – Returns a queued key, if one is available.Returns immediately with a null value, if unavailable. poll – Returns a queued key, if available.The order of events in an event processing loop follow: The following code snippet shows how to register a Path instance for all three event types: You do not have to register for the OVERFLOW event to receive it. OVERFLOW – Indicates that events might have been lost or discarded.ENTRY_MODIFY – A directory entry is modified.ENTRY_DELETE – A directory entry is deleted.ENTRY_CREATE – A directory entry is created.StandardWatchEventKinds event types follow: When registering an object with the watch service, you specify the types of events that you want to monitor. (The three-argument version takes a WatchEvent.Modifier, which is not currently implemented.) Register(WatchService, WatchEvent.Kind.). The Path class implements the Watchable interface, so each directory to be monitored is registered as a Path object.Īs with any Watchable, the Path class implements two register methods. Next, register one or more objects with the watch service. WatchService watcher = FileSystems.getDefault().newWatchService() Either run the program in a separate window, or in the background, as follows: ![]() WatchDir uses a single thread to process all events, so it blocks keyboard input while waiting for events. Create a test directory that will be passed to the example. WatchDir example to your computer, and compile it. You can dedicate aīecause this API is more advanced, try it out before proceeding. WatchKeys are thread-safe and can be used with the package.
0 Comments
Leave a Reply. |