디렉토리에는 n 개의 파일이 있습니다. 클래스를 생성하면 java arraylist를 사용하여 디렉토리에서 크기별로 파일을 정렬합니다.자바 배열 목록을 사용하여 크기별로 디렉토리에서 파일 정렬
파일 이름과 크기를 읽을 수 있습니다. 크기에 따라 파일을 정렬하는 방법은 무엇입니까?
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
public class SortingFiles
{
public static void main(String[] args)
{
File dir=null;
File[] paths;
final ArrayList<String> al= new ArrayList<String>();
try{
// create new file object
dir = new File("D:\\New folder\\New");
// array of files and directory
paths = dir.listFiles();
ArrayList<File> fileList = new ArrayList<File>();
for(File file:paths)
{
// prints filename and directory name
System.out.println(file.getName()+" - " +file.length());
al.add(file.getName());
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
내가 크기
for(int i=1; i<al.size(); i++)
{
System.out.println("\n Aftr : " +al.get(i));
}
하여 파일을 정렬 할 시도하지만이 작동하지 않습니다 .. 어느 하나가 me..I는 "수입 org.apache없이 노력하고 도움이 될 수 있습니다. commons.io.FileUtils; " 그래서 뭐 할까 ?
의 사용 가능한 복제 [I 자바의 디렉토리에있는 파일을 정렬 할 수 있는가? (http://stackoverflow.com/questions/8107001/how-can-i-sort-files-in-a-directory -in-java) & [이름, 크기 및 마지막으로 수정 한 디렉토리 목록을 정렬하는 방법은 무엇입니까?] (http://stackoverflow.com/questions/13091517/how-can-i-sort-a-directory-listing -according-to-name-size-and-last-modified) – OO7