File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 36486
    
  16
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: 1666
    
    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
 
Similar Threads
Problem in downloading JFreechart
Code from SCJP K&B Book won't compile
plugins not getting recognized!
how to change webstart's default download folder?
copy files from one folder to another in java