深层遍历---------dfs(递归)
package test; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.zip.InflaterInputStream; import javax.annotation.processing.FilerException; import privateclass.Filterby_Name; import privateclass.Filterby_hidden; import privateclass.Filterby_java; import privateclass.MyBufferedReader; public class Main { private static final String space_operator = " "; private static final double pi = Math.PI; private static final String LINE_SEPARATOR = System.getProperty("line.separator"); public static void main(String[] args) throws Exception { File file = new File("d:\文档"); listall(file,0); } public static void listall(File file,int deep) { System.out.println(getdeep(deep) + file.getName()); deep++; for(File x : file.listFiles()) { if(x.isDirectory()) { listall(x,deep); } else { System.out.println(getdeep(deep) + x.getName()); } } } public static String getdeep(int deep) { StringBuilder s = new StringBuilder(); for(int i = 0; i < deep; i ++) { s.append(" "); } return s.toString(); } }