public class FileWatcher extends Thread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
private File |
file |
private List |
fileListenerList |
private int |
interval |
private long |
lastmodified |
private Thread |
watcher |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
FileWatcher(File file)
Constructs a FileWatcher watching the specified File
|
FileWatcher(String filename)
Creates a new instance of FileWatcher by calling the FileWatcher( File )
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addFileListener(FileListener fileListener)
Adds FileListener
|
private void |
checkFile() |
FileListener[] |
getFileListeners()
Retrieve an array of FileListeners.
|
static void |
main(String[] args)
Used to test it all
|
void |
run()
Start the thread to call checkFile()
|
void |
setFile(File file)
Sets a new File to be watched.
|
void |
setInterval(int seconds)
Set the timer interval.
|
void |
start()
Start the Thread on its journey to scan for changes to the
file it is watching.
|
void |
stopWatching()
Tell thread to stop watching.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
private List fileListenerList
private int interval
private long lastmodified
public FileWatcher(String filename)
filename
- A String representing the path to the file to be watched.public FileWatcher(File file)
file
- The File to be watchedpublic void addFileListener(FileListener fileListener)
fileListener
- The FileListenerpublic void setInterval(int seconds)
seconds
- The number of seconds to set the interval when
to check for the changes to the file.public void stopWatching()
public void start()
public void run()
public FileListener[] getFileListeners()
public void setFile(File file)
file
- The File to be watchedprivate void checkFile()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses