Discuss / Java / 练习

练习

Topic source

o_0

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

import java.io.*;

import java.nio.file.*;

public class IOTest3 {

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

Path p = Paths.get("..", "HelloIdea");

printAll(p.normalize().toFile(), 0);

}

static void printAll(File f, int layer) throws Exception {

File[] fs = f.listFiles();

for(File file : fs) {

for(int i = 0; i < layer; i++ ) {

System.out.print("  ");

}

System.out.println(file.getName() + (file.isDirectory() ? "/" : ""));

if(file.isDirectory() && file.list().length > 0) {

printAll(file, layer + 1);

}

}

}


  • 1

Reply