I'm able to do this:
File images = new File(path);
File[] imageList = images.listFiles(new FilenameFilter(){
public boolean accept(File dir, String name)
{
return name.endsWith(".jpg");
}
});
I copied from an answer of stackoverflow !
Is there a way to listFile ok kind "directory" (folder) and to list by reverse alphabetical order ? ... And by reverse date ?
To sort file names or other columns (such as Date Modified) in Windows Explorer or in any Office dialog based on Explorer (Open, Save As, etc.), click on the column's title. One click will sort in ascending order, and the next click will reverse it to descending order, and so back and forth. Was this reply helpful?
I was getting an exception
IllegalArgumentException: Comparison method violates its general contract!
so I used this and it worked ok:
Arrays.sort(filesList, new Comparator<File>() {
@Override
public int compare(File a, File b) {
if(a.lastModified() < b.lastModified() )
return 1;
if(a.lastModified() > b.lastModified() )
return -1;
return 0;
}});
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