Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Watch a Folder

 
Costa Lamona
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is there some core java class that watches a folder so that when a file inserted into that folder something fires some event?

Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't think so, no.

That is not the way applications usually work; you work from the application towards the OS/file system.

Try a Timer and a TimerTask which interrogates the folder regularly and records whether there is any change to the number of files in the folder. Go through the java.io.File class for more details.
 
siva krishna pallapu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think we can do this with a thread which is running continiously iterating through a while loop and checking the folders last modifies time at regular intervals the folder.lastmodified() if there is change in the time we can fire an event . i hope so it works..
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the Apache Commons Virtual File System (VFS) classes to accomplish this if you don't feel like rolling your own.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic