Java 递归算法,遍历文件夹下的所有文件。

用递归算法遍历文件下的所有子文件夹和子文件

文件夹遍历方法

    public void getFileList(String strPath){       
       File f=new File(strPath); try { if(f.isDirectory()){ File[] fs=f.listFiles(); for(int i=0;i<fs.length;i++){ String fsPath=fs[i].getAbsolutePath();
                    System.out.printlen(fsPath); getFileList(fsPath); } }
else if(f.isFile()){ String fname=f.getAbsolutePath();
              System.out.printlen(fname);
  }else{ System.out.println("路径不正确!");  } }catch (IOException e) {   System.out.println("遍历异常"); }
      }
原文地址:https://www.cnblogs.com/baconLiu/p/6743232.html