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
At least in regular Java version you compare files in the wrong (ascending) order. I multiplied result by -1 and I am seeing latest files first:
return -1* (new Long(((File)o1).lastModified()).compareTo(new Long(((File) o2).lastModified())));
With timestamps the larger one corresponds to the newer file.
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.