Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)
Answer / Sumit Kumar Yadav
To list all files in a directory using Java's File class, you can use a recursive approach. Here's an implementation:n```npublic static void listFiles(File dir) {n if (dir.isDirectory()) {n File[] children = dir.listFiles();n for (File file : children) {n if (file.isDirectory()) {n System.out.println("Directory: " + file.getName());n listFiles(file);n } else {n System.out.println("File: " + file.getName());n }n }n }n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is finally and finalize in java?
Why are the objects immutable in java?
What is a final class ?
What is data type modifier?
What is the static field modifier?
What is a heavyweight component?
How do you write a scanner class in java?
what is webservices
5 Answers Consultancy, Mind Tree,
What is instance example?
If try block is successfully executed, Then Is Finally block executed?
Why we use set in java?
Is alive and join method in java?