This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
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 operations.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Assuming you use a Timer you can have a task the wakes up every n seconds and lists the contents of the directory. It could check this against some persistent list of file names stored when it last ran and copy any files not previously listed.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Please Use One Thread Per Question. Let's continue here.

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!