Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.io . File; public class DisplayDirectoryStructure { public static void main ( String [ ] args ) { / / Get user input for
import java.ioFile;
public class DisplayDirectoryStructure
public static void mainString args
Get user input for the directory path
System.out.printEnter the path: ;
Scanner scanner new ScannerSystemin;
String userPath scanner.nextLine;
scanner.close;
Display directory structure
displayDirectoryStructureuserPath;
public static void displayDirectoryStructureString path
int numFiles ;
int numDirectories ;
long totalSize ;
displayDirpath numFiles, numDirectories, totalSize;
Display summary
System.out.println
Number of Files: numFiles;
System.out.printlnNumber of Directories: numDirectories;
System.out.printlnTotal Size: totalSize bytes";
private static void displayDirString path, String prefix, int numFiles, int numDirectories, long totalSize
File directory new Filepath;
File entries directory.listFiles;
if entries null
for File entry : entries
if entryisFile
System.out.printlnprefix entry.getName entry.length bytes";
totalSize entry.length;
numFiles;
else if entryisDirectory
System.out.printlnprefix entry.getName;
numDirectories;
displayDirentrygetPath prefix numFiles, numDirectories, totalSize;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started