File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes how to check for the new file created in a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Reply locked New topic

how to check for the new file created in a directory

sudeep jha

Joined: Sep 05, 2007
Posts: 19
I need a very simple process that listens on a directory.When a new file is created on that directory,
the new file has to be copied to a remote location.
I have created the listener but how can I check for new file from the set of files in directory using java code.
There is no creationdate method in java file api.There is only one lastmodifed() method for the java file metadata operation.
How to achieve all these as a web service?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
Not that this has anything to do with webservices, but I suspect you need to use polling. That is, you submit a task to a ScheduledThreadPoolExecutor and the task regularly checks the contents of the director using File.listFiles() to determine if new files are present.
You can, if you wish, persist the state of the directory, but you need to decide on a policy in the case there is no previously persisted state, i.e. are present fiels new or old, as far as your "service" is concerned.
Best wishes!
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

What is the use of a web service here? You can just write a java program to keep polling the directory?

===Vyas Sanzgiri===
My Blog
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

Please Use One Thread Per Question. The only difference between this post and this one is the mention of web service. Not enough to warrant a new thread.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: how to check for the new file created in a directory
It's not a secret anymore!