I want list of file based on my creation date. When i updating any if images and trying to retrive all images,then orders are changed randomly.
Here is my code,
File[] files = parentDir.listFiles();
for (File file : files) {
// I am getting files here
}
Any help..
Click the sort option in the top right of the Files area and select Date from the dropdown. Once you have Date selected, you will see an option to switch between descending and ascending order.
List<File> fileList = new ArrayList<File>();
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File file1, File file2) {
long k = file1.lastModified() - file2.lastModified();
if(k > 0){
return 1;
}else if(k == 0){
return 0;
}else{
return -1;
}
}
});
I want list of file based on my creation date.
As the two previous answers pointed out, you can sort the files according to the modification date:
file.lastModified()
But the modification date is updated e.g. in the instant of renaming a file. So, this won't work to represent the creation date.
Unfortunately, the creation date is not available, thus you need to rethink your basic strategy:
see an old answer of CommonsWare
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With