Discuss / Java / 各种参考胡乱写的

各种参考胡乱写的

Topic source

Arthur

#1 Created at ... [Delete] [Delete and Lock User]

public class Main {

public static void main(String[] args) throws IOException {

File f=new File("E:\\BaiduNetdiskDownload");

String b="\t";

int depth=0;

printFile(f,b,depth);

}

static void printFile(File f,String b,int depth) {

if(f.isFile()) {

System.out.println(b.repeat(depth)+f.getName());

}else if(f.isDirectory()){

System.out.println(b.repeat(depth)+f.getName()+"/");

for(File ff:f.listFiles()) {

printFile(ff,b,depth+1);

}

}

}

}


  • 1

Reply