0

I am studying I/O streams, and I decided to write a program which displays a hierarchy of directory. The program takes an arguments as a Path, and it should display the hierarchy of the given path, if it is a directory.

Here is my Code:

import java.nio.file.Files;
import java.nio.file.Path;

public class Display {
  public String tree(Path path){
     if(path!=null){
        //if its a directory
         if(Files.isDirectory(path)){
            //No idea how to implement it :(
         }
        //if its a file
         else{
            return "Single File  No Hierarchy!";
         }
     }
    return null;
 } 
}

I want the result to be like this:

enter image description here

I would really appreciate if someone could explain, how can I display the hierarchy like this.

P.S it would be good to keep directories and files in lexicographic order, by case insensitive

0 Answers0