Posted by tech on
February 2, 2009
There came a point that I had to display a list of log files in a certain directory for my boss to view. The important thing with the list display is that the files should be sorted in descending order. From top would be the latest while the oldest would be down at the bottom. Java can do sorting through the Comparator Class. And luckily, I found a
post in a forum that saved me the time and trouble to make a custom method for it. The code looks like this.
public static void sortFilesDesc(File[] files) {
Arrays.sort(files, new Comparator() {
public int compare(Object o1, Object…
Continue reading