1import java.io.File;
2import java.io.IOException;
3public class ListOfFiles {
4 public static void main(String args[]) throws IOException {
5 //Creating a File object for directory
6 File directoryPath = new File("D:\\ExampleDirectory");
7 //List of all files and directories
8 File filesList[] = directoryPath.listFiles();
9 System.out.println("List of files and directories in the specified directory:");
10 for(File file : filesList) {
11 System.out.println("File name: "+file.getName());
12 System.out.println("File path: "+file.getAbsolutePath());
13 System.out.println("Size :"+file.getTotalSpace());
14 System.out.println(" ");
15 }
16 }
17}