This program simply sorts a folder of images files by size and outputs them to a new directory. However whenever I view the directory it is not maintained in the sorted order. Any solutions would be beneficial.
Here are the relevant code snippets
class CompareFileSize implements Comparator<File>{ public int compare(File s1, File s2) { long len1 = s1.length(); long len2 = s2.length(); if (len1 > len2){ return 1; }else if (len1 < len2){ return -1; }else return 0; } } public class FileSorter { public static void main(String[] args) throws IOException { File p = new File("C:\\Users\\PC\\Desktop\\newFolder"); File f = new File("C:\\Users\\PC\\Desktop\\oldFolder"); File myPics [] = f.listFiles(); ArrayList<File> aList = new ArrayList<File>(); for (int i = 0; i < myPics.length; i++){ aList.add(myPics[i]); } System.out.println("Before----------------------------------------"); for (File uimage: aList){ System.out.println(uimage); } System.out.println("After-----------------------------------------"); Collections.sort(aList, new CompareFileSize()); for (File image: aList){ System.out.println(image); FileUtils.copyFileToDirectory(image, p); } } }