There is a task:
Request the path to the folder from the console, get a list of all folders of the specified folder, taking into account the hierarchy.
For example, a search in the "book" folder will give 5 items:
-book --directory1 ---file1 ---file2 --directory2 ---directory3 ----directory4 -----directory5 ------file3 A partial implementation looks like this:
public static void main(String[] args) { String scan = new Scanner(System.in).nextLine(); System.out.println(scan); File dir = new File(String.valueOf(scan)); if ( dir.isDirectory() ) { File[] files = dir.listFiles(); for ( File tmpFile : files ) { System.out.println("-" + tmpFile.getName()); if ( tmpFile.isDirectory() ) { File[] tmpFile1 = tmpFile.listFiles(); for ( File file3 : tmpFile1 ) { System.out.println("--" + file3.getName()); } } } } } Result:
d://book -directory1 --file1.txt --file2.txt -directory2 --directory3 The result gives the data only to the third directory, and I'll never know how to fix the code and complete the task.