Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

can java list file and sort it by modified time.

Thread view: 
gdevah@gmail.com - 09 Mar 2007 07:08 GMT
Hi, I am looking for efficient api to implement "ls -lrt" command in
java,
Thanks in advance
Regards,
Devah
Nigel Wade - 09 Mar 2007 15:26 GMT
> 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"?

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Daniel Pitts - 09 Mar 2007 20:57 GMT
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());
       }
   }

}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.