Tutorialspoint examples

Learn java tutorial with examples for beginners online

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.tutorialspointexamples;
 
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.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status