wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to write a File Listener" Watch "how to write a File Listener" New topic
Author

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?


Thanks,
Kumar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Read the ASF license for ASF license details.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to write a File Listener
 
Similar Threads
how to check for the new file created in a directory
how to check for the new file created in a directory
Dragging a file from swt to windows file system
The ULTIMATE! From the creator of FileMonitor comes DirectoryMonitor :)
how to check for the new file created in a directory