jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Watch a Folder" Watch "Watch a Folder" New topic

Watch a Folder

Costa Lamona

Joined: Sep 17, 2006
Posts: 29

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

Campbell Ritchie

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

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

Joined: Mar 10, 2008
Posts: 1951

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
It's not a secret anymore!