Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

how to check for the new file created in a directory

 
sudeep jha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 686
Chrome Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
What is the use of a web service here? You can just write a java program to keep polling the directory?
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic