• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting Array of files by descending date and time format  RSS feed

 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ahve list of txt filesin 'n directory
rolebased071607001038042.txt
crf-crf072307001037051.txt
crfonlyd073107001037060.txt

The above filenames contain the following (taking the first file as an example):
rolebased - This is the rolebasedinformation
071607 - This is the date (mmddyy)
001038042- This is the time including milliseconds(00:10:38:042 AM)


I need to sort these files descendingly according to date and then time (process the oldest files first, and the newest files last).
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several sorting implementations in the Java library that know everything but how to compare two items. You can provide the comparison logic in a Comparable method on the objects, or in a separate Comparator object. If you're working with String or File objects, you want to make a Comparator.

See Arrays.sort() or TreeSet(comparator). Try to write something using one of these - it should only be a few lines long - and show us what you make!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!