Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to sort files in a Directory based on Date and Time

 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me how to sort files in a Directory based on Date and Time?

thanks in advance
Ramesh
 
Sujith Kanaparthi
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The public long lastModified() of java.io.File can used for sorting based on date and time of last modification of file

Regards,
sujith
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sujith,

thanks for the reply, can you pls send me code snippet to develop this

Thanks
Ramesh
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh, look at the API documentation of class java.io.File. It contains methods like list() and listFiles() to get an array of File objects that represent the files in the directory.

After getting the array you can sort it using Arrays.sort(), you should implement a Comparator object to compare the files by date.

Please try writing some code yourself, and if you get stuck, show us your code and tell us where you get stuck.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic