adspace
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 Posted / 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 |
Post New Answer View All Answers
Is minecraft 1.15 out?
Write a program to find the whether a number is an Armstrong number or not?
How to create a base64 decoder in java8?
What is the difference between equals() and == in java?
What do you mean by an interface in java?
What are the differences between heap and stack memory in java?
What is parsing in java?
Explain public static void main(string args[]) in java.
explain different ways of using thread? : Java thread
Differentiate between static and non-static methods in java.
Realized?
Write a program to print count of empty strings in java 8?
What is a classloader in java?
What is java string pool?
How to sort array in descending order in java?