public class TreeTest {
public static void main(String[] args) {
showDir(1, new File("D:\\test"));
}
static void showDir(int indent, File file) {
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]);
}
}
}
Java: using recursion to read a folder and its content in tree format sub-folders/files in tree format
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment
Your Comment and Question will help to make this blog better...