read and existing dir content in java

Solutions on MaxInterview for read and existing dir content in java by the best coders in the world

showing results for - "read and existing dir content in java"
Curtis
21 Jul 2017
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}