SSISO Community

시소당

Reading and Printing a Directory Hierarchy

import  java.io.File;
import  java.io.IOException;

public  class  FileUtil  {
    public  static  void  main(String[]  a)throws  IOException{
        showDir(1,  new  File("d:\\Java_Dev"));
    }
    static  void  showDir(int  indent,  File  file)  throws  IOException  {
        for  (int  i  =  0;  i  <  indent;  i++)
            System.out.print('-');
        System.out.println(file.getName());
        if  (file.isDirectory())  {
            File[]  files  =  file.listFiles();
            for  (int  i  =  0;  i  <  files.length;  i++)
                showDir(indent  +  4,  files[i]);
        }
    }
}

입력한  폴더의  하위  자료구조를  출력해  주는  예제

1064 view

4.0 stars