• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sonal Sharma
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic