To achieve the purpose of putting all the files under the development directory, print them out in a tree-like structure. The code is as follows:
Package Cn.bjsxt.io;
Import Java.io.File;
public class Filetree {
public static void Main (string[] args) {
File F=new file ("e:/useful Document"); Suppose you print all the files in this directory
Printtree (f, 0); Starting from itself, from 0
}
public static void Printtree (File f,int level) {
for (int i=0;i<=level-1;i++) {
System.out.print ("-"); Not at first--one more "-" in front of the first-level catalogue
}
System.out.println (F.getname ());
if (F.isdirectory ()) {
File[] Files=f.listfiles ();
for (File j:files) {
Printtree (j,level+1); To enhance the For loop, J is the parameter. Each end is then used Printtree (),
Level levels are added one at a time.
}
}
}
}
JAVA File class Print directory tree structure graph recursive algorithm