Demonstrate your understanding of tree data structure Write
Demonstrate your understanding of tree data structure: Write a Java program in pseudo code to accomplish the following tasks: Identify and display the number of files in the current directory where the file is located.
Solution
import java.io.File;
public class CurrentDirectory {
public static void main(String[] args) {
File currentDir = new File(\"\").getAbsoluteFile();
File[] listOfFiles = currentDir.listFiles();
int count = 0;
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println(\"File \" + listOfFiles[i].getName());
count++;
} else if (listOfFiles[i].isDirectory()) {
System.out.println(\"Directory \" + listOfFiles[i].getName());
}
}
System.out
.println(\"Number of files in the current directory: \" + count);
}
}
OUTPUT:
File .classpath
File .project
File babynamerank2006.txt
Directory bin
Directory src
Number of files in the current directory: 3
