如何列出某个目录下的所有文件 

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【FEIFEI12345678】截止到2008-07-07 13:25:23的历史汇总数据(不包括此帖):
    发帖的总数量:10                       发帖的总分数:170                      
    结贴的总数量:6                        结贴的总分数:100                      
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:4                        未结的总分数:70                       
    结贴的百分比:60.00 %               结分的百分比:58.82 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

    子目录下的文件也要的话:import java.io.*;class Test1 {
    static void getDir(String strPath) throws Exception {
    try {
    File f = new File(strPath);
    if (f.isDirectory()) {
    File[] fList = f.listFiles();
    for (int j = 0; j < fList.length; j++) {
    if (fList[j].isDirectory()) {
    System.out.println(fList[j].getPath());
    getDir(fList[j].getPath()); // 在getDir函数里面又调用了getDir函数本身
    }
    }
    for (int j = 0; j < fList.length; j++) { if (fList[j].isFile()) {
    System.out.println(fList[j].getPath());
    } }
    }
    } catch (Exception e) {
    System.out.println("Error: " + e);
    } } public static void main(String[] args) {
    String strPath = "C:\\Documents and Settings\\All Users\\Documents\\My Music"; System.out.println(strPath); try {
    getDir(strPath);
    } catch (Exception e) { }
    }
    }
      

  3.   

    String[] fs=new File(localRoot).list();
      if ((fs == null) || (fs.length <= 0)) {
    System.out.println("空文件夹");
    return;
      }
      for(String s:fs){
      System.out.println(s);
      }
      

  4.   


    String[] fs=new File(localRoot).list(); 
      if ((fs == null) || (fs.length <= 0)) { 
    System.out.println("空文件夹"); 
    return; 
      } 
      for(String s:fs){ 
      System.out.println(s); 
      }
      

  5.   

    public static void getAllDirectoryAndFile(String strPath){
    try {
     File[] fList = new File(strPath).listFiles();
      if ((fList == null) || (fList.length <= 0)) {
    System.out.println("空文件夹");
    return;
      }else{
      for(File s:fList){
      System.out.println(s.getPath());
      getAllDirectoryAndFile(s.getPath());
      }
      }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }