java : Sort Files based on Creation Date

前端 未结 2 646
野性不改
野性不改 2021-01-15 02:02

I am trying to read the latest 10 files based on their creation date .

I tried with this code , but it isn\'t working , i mean , it doesn\'t show the new file nam

2条回答
  •  无人共我
    2021-01-15 02:31

    Try flipping the comparison order:

    return new Long(((File)o2).lastModified()).compareTo(new Long(((File) o1).lastModified()));
    

    This works for me testing locally just now.

提交回复
热议问题