Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to write a File Listener

 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the ASF license for ASF license details.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic