This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes getting all the files from a directory for latest date,time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting all the files from a directory for latest date,time" Watch "getting all the files from a directory for latest date,time" New topic
Author

getting all the files from a directory for latest date,time

Sonal Sharma
Ranch Hand

Joined: May 13, 2006
Posts: 62
I want to read the latest files in a directory by comparing its date and time of last creation or modification.Can somebody suggest a way to do it?
Any code snippet or tutorial will be highly appreciated.Please try to explain in detail.



Thanks and regard
--Sonal
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

File.listFiles is the method, then call the lastModified() method on each File to get the modification date. Please note that the creation date is NOT available.

The comparison is quite easy; check java.utils.Arrays which has a sort method, you'll need to create a Comparator implementation for that which compares on lastModified().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting all the files from a directory for latest date,time