使用递归调用检索该目录下的文件

13年前
package com.test.code;    import java.io.File;  import java.util.ArrayList;  import java.util.Iterator;  import java.util.List;    /**   * 使用递归调用检索该目录下的文件   * @author 蒋全忠   *   */  public class Digui {   private static List<String> fileList = new ArrayList<String>();     public static List<String> searchFile(String path) {    File file = new File(path);    File[] files = file.listFiles();    if (files == null) {     return null;    } else {     for (int i = 0; i < files.length; i++) {      if (files[i].isDirectory()) {       fileList.add(files[i].getPath());       searchFile(files[i].getAbsolutePath());      } else {       fileList.add(files[i].getPath());      }     }    }    return fileList;   }     public static void main(String[] args) {    String path = "c:\\Aptana RadRails";    long start = System.currentTimeMillis();    List<String> files = searchFile(path);    System.out.println("共有文件数量:" + files.size());    System.out.print("总共用时:");    System.out.println(System.currentTimeMillis() - start);    Iterator<String> i = files.iterator();    while (i.hasNext()) {     System.out.println(i.next());    }     }  }