Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > can java list file and sort it by modified time.

Reply
Thread Tools

can java list file and sort it by modified time.

 
 
gdevah@gmail.com
Guest
Posts: n/a
 
      03-09-2007
Hi, I am looking for efficient api to implement "ls -lrt" command in
java,
Thanks in advance
Regards,
Devah

 
Reply With Quote
 
 
 
 
Nigel Wade
Guest
Posts: n/a
 
      03-09-2007
wrote:

> Hi, I am looking for efficient api to implement "ls -lrt" command in
> java,


The File class can handle the modification time. The sorting can be done by a
List in conjunction with Collections.sort(). As for efficient, what is your
definition of "efficient"?

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail :
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      03-09-2007
On Mar 8, 11:08 pm, gde...@gmail.com wrote:
> Hi, I am looking for efficient api to implement "ls -lrt" command in
> java,
> Thanks in advance
> Regards,
> Devah

Learning by example:
public class ModifiedFileList {
public static void main(String[] args) {
File[] files = new File(args[0]).listFiles();
Arrays.sort(files, new Comparator<File>() {
public int compare(File o1, File o2) {
return o1.lastModified() < o2.lastModified() ? -1 :
o1.lastModified() == o2.lastModified() ? 0 :
1;
}
});
for (File file: files) {
System.out.println(file.lastModified() + ": " +
file.toString());
}
}

}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP!! anyone ??can help me about my project "quick sort implemented with shell sort? comsciepartner General Computer Support 0 10-06-2008 01:02 PM
Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute cjt22@bath.ac.uk Python 7 09-10-2007 11:10 AM
can Perl Sort do this, unix sort breaks on it (muliple spaces as demiliter) colin_lyse Perl Misc 1 02-03-2005 01:13 AM
how to sort files my date last modified? SlowwHand Computer Support 3 10-16-2003 06:43 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments