I\'m able to do this:
File images = new File(path);
File[] imageList = images.listFiles(new FilenameFilter(){
public boolean accept(File
The right way to order files by date of last modified in reverse mode is doing:
Arrays.sort(Files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
for this instruction you will need the commons.io library from org.apache that you can download from here
For sort based on file name,Add
object1.getName().toLowerCase(Locale.getDefault())
instead of
object1.getName()
to avoid sort issues causing by Locale changes and upper/low case filenames
final File[] sortedFileName = images.listFiles();
if (sortedFileName != null && sortedFileName.length > 1) {
Arrays.sort(sortedFileName, new Comparator<File>() {
@Override
public int compare(File object1, File object2) {
return object1.getName().toLowerCase(Locale.getDefault()).compareTo(object2.getName().toLowerCase(Locale.getDefault()));
}
});
}
If you prefer brevity:
File[] files = folder.listFiles();
Arrays.sort(files, (a, b) -> Long.compare(b.lastModified(), a.lastModified()));