import java.io.File; /** * 递归遍历 * */ public class FieTree { public static void main(String[] args) { File f = new File("D:/java笔记"); printFile(f,0); } static void printFile(File file,int level){ for(int i=0;i<level;i++){ System.out.print("-"); } // if(level!=0){ // System.out.println("-"); // } System.out.println(file.getName()); if(file.isDirectory()){ File[] files = file.listFiles(); for(File temp:files){ printFile(temp,level+1); } } } }
转载于:https://www.cnblogs.com/zychengzhiit1/p/4735420.html