File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Implementing listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Implementing listeners" Watch "Implementing listeners" New topic

Implementing listeners

srinivasan ganesan
Ranch Hand

Joined: Mar 09, 2001
Posts: 54
Our app (built using servlets & jsps) runs on an application server. I have a situation where I need to know if a file is present in a particular location. This file is created after the user logs on and it will be posted in a certain location. I'm trying to implement a listener so that I can give the file to the user after it has been created and posted.
Any ideas on how to to achieve this? Also, if you have any questions, please let me know.
Thanks in advance,
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Well, you can create a thread that sleeps most of the time, but every second/minute/hour/whatever wakes up and looks for the file. You can check for a specific file name, or use File.listFiles() combined with File.lastModified() to search for any new files in a particular directory.

"I'm not back." - Bill Harding, Twister
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
You can use java.util.Timer and java.util.TimerTask to do as Jim has mentioned.
Or you can use Oberver and Observable Pattern.
I agree. Here's the link:
subject: Implementing listeners
It's not a secret anymore!