Here is my code and it works ! But I want to be able to sort the files list according to name, size, modification date and more
import java.io.File;
import org.apache.commons.io.FileUtils;
public class StartingPoint {
public static void main(String[] args) {
File file = new File(
"/home/t/lectures");
File[] files = file.listFiles();
for (File f : files) {
System.out.println("File : " + f.getName() + " ["
+ FileUtils.byteCountToDisplaySize(f.length()) + "]");
}
}
}
Example in Java8 to sort by last modification time:
then you may convert sortedList to Array or continue using lambda expressions with .forEach:
You could define a bunch of different
Comparator
classes to do different comparisons like such:Then you would just swap em out:
or