What is the easiest way to sort the output of this code by size from largest to smallest
If you want to sort by size try the following code:
Arrays.sort(files, new Comparator<File>() {
public int compare(File file1, File file2) {
return Long.compare(file2.length(), file1.length()); // or apply your logic
}
});
Where files
is an array of File
[UPDATE]
length()
returns long value... updated (based on comment by lassana)