Package hec.io
Class FileMonitor
java.lang.Object
hec.io.FileMonitor
Class for monitoring changes in disk files.
Usage:
1. Implement the FileListener interface.
2. Create a FileMonitor instance.
3. Add the file(s)/directory(ies) to listen for.
fileChanged() will be called when a monitored file is created,
deleted or its modified time changes.
-
Constructor Summary
ConstructorsConstructorDescriptionFileMonitor
(long pollingInterval) Create a file monitor instance with specified polling interval. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFile
(File file, FileListener listener) Add file to listen for.boolean
static void
Test this class.void
removeFile
(File file) Remove specified file for listening.void
removeListener
(File file, FileListener fileListener) Remove listener from this file monitor.void
stop()
Stop the file monitor polling.void
updateLastModified
(File file, long time) manually update the last modified time of a file
-
Constructor Details
-
FileMonitor
public FileMonitor(long pollingInterval) Create a file monitor instance with specified polling interval.- Parameters:
pollingInterval
- Polling interval in milli seconds.
-
-
Method Details
-
stop
public void stop()Stop the file monitor polling. -
addFile
Add file to listen for. File may be any java.io.File (including a directory) and may well be a non-existing file in the case where the creating of the file is to be trepped.More than one file can be listened for. When the specified file is created, modified or deleted, listeners are notified.
- Parameters:
file
- File to listen for.
-
updateLastModified
manually update the last modified time of a file- Parameters:
file
-time
-
-
removeFile
Remove specified file for listening.- Parameters:
file
- File to remove.
-
contains
-
removeListener
Remove listener from this file monitor.- Parameters:
fileListener
- Listener to remove.
-
main
Test this class.- Parameters:
args
- Not used.
-