Folder Read Example in Java

 /*  
 ListFiles: This program list All the files in the given folder.
 Author: Afiz  
 */  
 import java.io.File;  
 class ListFiles   
 {  
      public static void main(String[] args) // Main method   
      {  
       String path = ".."; // Directory path here  
       String files;  
       File folder = new File(path);  
       File[] listOfFiles = folder.listFiles(); // get files in the array   
       for (int i = 0; i < listOfFiles.length; i++) // iterate until last file  
       {  
             if (listOfFiles[i].isFile()) // can filter for different files(.txt or .mp3)  
             {  
                  files = listOfFiles[i].getName();  
                  System.out.println(files);  
             }  
       }  
      }  
 }  

Post a Comment

0 Comments