java_模拟dos文件夹树

最新代码见: http://blog.csdn.net/huitoukest/article/details/50516026
import java.io.File;

public class FileTree {
	public static void main(String args[]) {
		File h = new File("H:/");
		
		tree(h,0);
	}

	private static void tree(File f,int deep) {
		if(f.isDirectory()&&deep!=0)
		{String ss="";  
		 int k=deep;
		 while(k>0)
  		{ ss=ss+"    |";
		 k--;
		 }
		  ss=ss+"____";		
		System.out.print(ss);
		 }
		
		
		File[] childs = f.listFiles();// 列出当前目录中所有子目录
		for (int i = 0; i < childs.length; i++) {
			if (childs[i].isDirectory())
				{
                  System.out.println(childs[i].getName());
                 
                  tree(childs[i],deep+1);
		        }
		}
		
	}
}

java_模拟dos文件夹树_第1张图片

你可能感兴趣的:(java,递归,文件)