Results 1 to 9 of 9
Thread: Writing a file listener
- 04-08-2009, 04:15 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
-
I've never done a file listener, so sorry but I can't help you, but I can wish you a happy Matzah week.
- 04-08-2009, 04:42 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
Do you think I should post this in the "advanced" section?
-
I'm not sure. If you do decide to do this though, post links from one post to the other.
- 04-08-2009, 06:07 AM #5
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
You have to poll every so often to see if lastModified has changed. There is no event service from the file system in java.
- 04-08-2009, 01:22 PM #6
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
If I wanted to poll it every 20 seconds, how would I do that?
- 04-08-2009, 07:45 PM #7
With a Timer.
db
- 04-08-2009, 09:00 PM #8
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
I've done google searches on this. I've looked at websites/tutorials. I know that I need to use a timer and a filelistener. But how do I write the code? I understand what I need to use by not how to use it.
- 04-09-2009, 03:41 PM #9
Member
- Join Date
- Mar 2009
- Posts
- 22
- Rep Power
- 0
I've never heard of a filelistener interface.. My guess would be to use a Timer and a TimerTask, in some way like this
Start the timer something like this
And you need an implementation of TimerTask, which will work somewhat similar to a listenerJava Code:import java.util.Timer; public class SomeClass { private static final long TIME_TO_START = ...; private static final long DELAY_BETWEEN_POLLS = ...; Timer timer = new Timer(); // ... public void startFilePoller(File file) { timer.scheduleAtFixedRate(new FileListener(file), TIME_TO_START, DELAY_BETWEEN_POLLS); } //...
Hope this can get you startedJava Code:public class FileListener extends TimerTask { // ... public FileListener(File file, ..) { this.file = file; //.. } @Override public void run() { if (isFileModified()) { // do whatever needs doing if file has been modified } } private boolean isFileModified(){ //...
Similar Threads
-
Writing to DAT or TXT file
By hunterbdb in forum Advanced JavaReplies: 7Last Post: 10-12-2008, 02:50 PM -
swapping the contents of the file and writing to another file
By Ms.Ranjan in forum New To JavaReplies: 9Last Post: 07-10-2008, 04:52 PM -
Writing to a file (at the end)
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:22 AM -
writing to a file
By bugger in forum New To JavaReplies: 1Last Post: 11-11-2007, 02:49 AM -
Help with File reading and writing
By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks