File path=new File("D:\\aa\\bb";
File[] fileList=path.listFiles();

解决方案 »

  1.   

    File path=new File("D:\\aa\\bb");
    File[] fileList=path.listFiles();
      

  2.   

    呵呵,今天性能调优成果不错,提高了一倍!心情好,写点小代码吧。哈哈import java.io.File;
    import java.util.HashMap;
    import java.util.Iterator;
    public class FileList {
    private String path;
    private HashMap localList = new HashMap();
    private long size = 0L;

    public FileList(String path) {
    this.path = path;
    File dir = new File(path);
    getDirectory(dir);
    }

    public void getDirectory(File file) {


    File[] fileList = file.listFiles();
    if (fileList == null) {
    localList.put(file.getAbsolutePath(), file);
    size += file.length();
    return;
    }

    for (int i = 0; i < fileList.length; i++) {

    localList.put(fileList[i].getAbsolutePath(), fileList[i]);
    size += fileList[i].length();
    if (fileList[i].isDirectory()) {
    getDirectory(fileList[i]); //递归
    }
    }
    }
    public HashMap getLocalList() {
    return localList;
    }

    public long getSize() {
    return size;
    }

    public static void main (String args[]) { FileList fl = new FileList("E:\\work\\Test");
    System.out.println("size " + fl.getSize());
    HashMap hm = fl.getLocalList();
    System.out.println("file count " + hm.size() );
    Iterator a = hm.keySet().iterator();
    while (a.hasNext()) {
    System.out.println((String)a.next());
    }

    }
    }
      

  3.   

    出错啦!C:\Documents and Settings\Administrator\桌面\Test.java:6: class FileList is public, should be declared in a file named FileList.java
    public class FileList 
           ^
    1 error