CodesJava

Easy learning with example program codes

read all files from folder java get list program

The listFiles() method of File class is used to get the list of files in the folder or directory.

Example:

package com.codesjava;
 
import java.io.File;
 
public class ListFiles {
  public static void main(String args[]){
	 File file = new File("D:/Test files/");
	 File[] files = file.listFiles();
     for(File f: files){
         System.out.println(f.getName());
     }
  }
}

Output:

file1.docx
file2.docx
newTest.txt

Download this example.

Please follow and like us:
error
Posted in IO   








Copyright © 2019 CodesJava DMCA.com Protection Status