It is easier to display the names of specific folders, files, subfolders, and subfolders in the command line using recursive calling (calling the parent method). The following is an example:Code:
Import Java. io. *; public class filelist {public static void main (string [] ARGs) {file F = new file ("D:/a"); system. out. println (F. getname (); // obtain the name tree (F, 1) of the F folder;} Private Static void tree (file F, int level) {string prestr = ""; for (INT I = 0; I <level; I ++) // insert Space {prestr + = "";} file [] Childs = f. listfiles (); // obtain the subfolders and subfolders of the f folder, and return the array for (INT I = 0; I <Childs. length; I ++) {system. out. println (prestr + Childs [I]. getname (); // name of the Output Folder if (Childs [I]. isdirectory () {tree (Childs [I], level + 1); // call the parent method }}}}