Below is a test Timertask class that i have been experimenting with. Basically the timertask watches when a file changes and then executes some methods. I want a message printed to the user, eg."Waiting for file change to occur" as long as the timertask is running . Where should the command be input?. Below is my code.
Thanks!
public class FileWatcherTest {
static int count = 3;
static int i = 0;
public static void main(String[] args) {
final Timer timer = new Timer();
System.out.println("Starting Timer " + timer.toString());
TimerTask task = new FileWatcher(new File("c:/temp/text.txt")) {
protected void onChange(File file) {
i++;
System.out.println("Executing iteration " + i);
System.out.println("File " + file.getName() +
" have change !");
// code to cancel timer
if (i >= count) {
System.out.println("Finished Iterations");
System.out.println("Stopping Timer");
timer.cancel();
System.out.println("Stopped Timer");
} else {
}
}
};
// repeat the check every second
timer.schedule(task, new Date(), 1000);
}
}