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


Please Help Members By Posting Answers For Below Questions

Is minecraft 1.15 out?

1045


Write a program to find the whether a number is an Armstrong number or not?

1096


How to create a base64 decoder in java8?

1135


What is the difference between equals() and == in java?

1037


What do you mean by an interface in java?

1100


What are the differences between heap and stack memory in java?

1135


What is parsing in java?

1039


Explain public static void main(string args[]) in java.

1074


explain different ways of using thread? : Java thread

1080


Differentiate between static and non-static methods in java.

1126


Realized?

2259


Write a program to print count of empty strings in java 8?

1084


What is a classloader in java?

1086


What is java string pool?

1080


How to sort array in descending order in java?

994