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);
            }
        }
    }
}

相关文章:

  • 2021-12-16
  • 2021-10-16
  • 2022-12-23
  • 2021-11-09
  • 2022-03-03
  • 2022-01-09
  • 2022-01-22
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2021-06-08
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案