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


Win a copy of Android Security Essentials Live Lessons this week in the Android 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: 38045
    
  22
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: 1756
    
    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
how to change webstart's default download folder?
copy files from one folder to another in java
Code from SCJP K&B Book won't compile
plugins not getting recognized!
Problem in downloading JFreechart