I've (as a Java beginner) got the following problem. I want to Display the Tree hierarchy from a directory (same or kind of the same you can do with windows CMD with: tree C:/)
hope for quick response
I've (as a Java beginner) got the following problem. I want to Display the Tree hierarchy from a directory (same or kind of the same you can do with windows CMD with: tree C:/)
hope for quick response
You can get the whole File System hierarchy using File.listFiles()
The listFiles()
method in java.io.File
lists the files in a directory. Starting from there, you can go through the directory tree recursively:
public static void main(String[] args)
{
listDirectory(new File("C:/"), 0);
}
private static void listDirectory(File directory, int level)
{
for(File file : directory.listFiles())
{
for(int i = 0; i < level; i++)
System.out.print('\t');
System.out.println(file.getName());
if(file.isDirectory())
listDirectory(file, level + 1);
}
}