Here you can find the source of getFilesByDate(String directory, final boolean earliestFirst)
public static File[] getFilesByDate(String directory, final boolean earliestFirst)
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; public class Main { public static File[] getFilesByDate(String directory, final boolean earliestFirst) { File[] files = new File(directory).listFiles(); Arrays.sort(files, new Comparator<File>() { @Override// w w w. jav a2 s. c o m public int compare(File o1, File o2) { if (earliestFirst) { return new Long(o1.lastModified()).compareTo(new Long(o2.lastModified())); } else { return new Long(o2.lastModified()).compareTo(new Long(o1.lastModified())); } } }); return files; } public static String[] listFiles(String fileName) { return listFiles(new File(fileName)); } public static String[] listFiles(File file) { List<String> files = new ArrayList<String>(); File[] fileArray = file.listFiles(); if (fileArray != null) { for (int i = 0; i < fileArray.length; i++) { if (fileArray[i].isFile()) { files.add(fileArray[i].getName()); } } } return (String[]) files.toArray(new String[0]); } }