Discuss / Java / 也没啥好说的,递归了

也没啥好说的,递归了

Topic source
public class Code01 {
    public static void main(String[] args) {
        String pathName;
        if (args.length == 0)
            pathName = ".";
        else pathName = args[0];
        printFile(pathName);

    }
    public static void printFile(String pathName){
        Path path = Paths.get(pathName);
        File file = path.toFile();
        File[] list = file.listFiles();
        for (File f : list) {
            System.out.println(f.getAbsolutePath());
            if (f.isDirectory()) {
                printFile(f.getAbsolutePath());
            }
        }
    }
}


  • 1

Reply