This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Reply locked New topic
Author

how to check for the new file created in a directory

sudeep jha
Greenhorn

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
    
    1
Hi!
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
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to check for the new file created in a directory
 
Similar Threads
IO
passing file directory to function
File I/O
how to check for the new file created in a directory
how to check for the new file created in a directory