递归显示目录结构

递归显示目录结构

import java.io.File;

public class Test12 {

    public static void main(String[] args) {
        showDirectory(new File("D:\\tools\\小米5深度刷机\\深度工具"));
    }

    private static int level = 0;

    private static void showDirectory(File f) {
        if(f.isDirectory()) {
            for(int i = 0; i < level; i++) {
                System.out.print("\t");
            }
            System.out.println("D-"+f.getName());
            level++;
            for(File temp : f.listFiles()) {
                showDirectory(temp);
            }
            level--;
        } else {
            for(int i = 0; i < level; i++) {
                System.out.print("\t");
            }
            System.out.println("F-"+f.getName());
        }
    }
}

你可能感兴趣的:(递归显示目录结构)