can java list file and sort it by modified time.

Discussion in 'Java' started by gdevah@gmail.com, Mar 9, 2007.

  1. Guest

    Hi, I am looking for efficient api to implement "ls -lrt" command in
    java,
    Thanks in advance
    Regards,
    Devah
     
    , Mar 9, 2007
    #1
    1. Advertising

  2. Nigel Wade Guest

    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
     
    Nigel Wade, Mar 9, 2007
    #2
    1. Advertising

  3. Daniel Pitts Guest

    On Mar 8, 11:08 pm, 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());
    }
    }

    }
     
    Daniel Pitts, Mar 9, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anusha.boggarapu

    open a file based on the modified time

    anusha.boggarapu, Feb 4, 2009, in forum: Java
    Replies:
    0
    Views:
    390
    anusha.boggarapu
    Feb 4, 2009
  2. Navin
    Replies:
    1
    Views:
    767
    Ken Schaefer
    Sep 9, 2003
  3. Vetrivel Vetrivel
    Replies:
    1
    Views:
    116
    Vetrivel Vetrivel
    May 26, 2009
  4. Guest
    Replies:
    2
    Views:
    193
    J. Gleixner
    Oct 1, 2004
  5. Robin

    file modified thinggummy and time

    Robin, Jun 20, 2010, in forum: Perl Misc
    Replies:
    1
    Views:
    117
    Uri Guttman
    Jun 20, 2010
Loading...

Share This Page