Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to check for the new file created in a directory

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic