import java.io.File; import java.util.Scanner;
/** * This program lists the files in a directory specified by * the user. If one of those files is itself a directory, the * program recursively lists the contents of that subdirectory. * The user is asked to type in the name of the directory that is * to be listed. If the name entered by the user is not a directory, * a message is printed and the program ends. */ public class RecursiveDirectoryList {
public static void main(String[] args) {
String directoryName; // Directory name entered by the user. File directory; // File object referring to the directory. Scanner scanner; // For reading a line of input from the user.
scanner = new Scanner(System.in); // scanner reads from standard input.
…show more content…
listDirectoryContents(directory,""); }
} // end main()
/** * A recursive subroutine that lists the contents of a directory, * including the contents of its subdirectories to any level of nesting. * @param dir the directory whose contents are to be listed. It is