This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to write a File Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to write a File Listener" Watch "how to write a File Listener" New topic

how to write a File Listener

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
In our requirement, we have an empty directory, when we drop a file in that directory, we need to read that file according to the API (that I have implemented and tested in standalone). How to load that file as soon as drop that into that directoru, and need to wait that listener till the complete file droped. how can we implement that code?

Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Check out Apache Commons VFS, especially its FileMonitor interface and DefaultFileMonitor implementation. Although that does not notify you immediately, it's polling each second so you get notified within a second.

If you need actual direct notification you may be able to use JNI to connect to the file system, but a) this is a lot more complex, and b) it's file system dependant (FAT32 would probably need to have different code than NTFS and EXT2/EXT3).

How To Ask Questions How To Answer Questions
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
Hi Rob,

Thanks for giving the way to get into this, I have couple of questions.
Is this free to use these libraries?
2)Do we have any examples to load the file when we drop into the folder?
David Newton

Joined: Sep 29, 2008
Posts: 12617

Read the ASF license for ASF license details.
I agree. Here's the link:
subject: how to write a File Listener
It's not a secret anymore!