This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Java in General and the fly likes Watch a Folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Watch a Folder" Watch "Watch a Folder" New topic
Author

Watch a Folder

Costa Lamona
Greenhorn

Joined: Sep 17, 2006
Posts: 29
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

Joined: Oct 13, 2005
Posts: 40029
    
  28
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

Joined: Aug 12, 2008
Posts: 7
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

Joined: Mar 10, 2008
Posts: 1836
    
    7

You could use the Apache Commons Virtual File System (VFS) classes to accomplish this if you don't feel like rolling your own.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Watch a Folder