How to find list of files in a folder using java

The following  example shows how to get list of all file names from the given folder. First create File object by passing folder path. Call list() method on file object to get list of file names in the folder


package com.onlinecodegeek.javase;
import java.io.File;

public class ListFilesFromFolder {

public static void main(String a[]){
File file = new File("C:/Temp/");
String[] fileList = file.list();
for(String name:fileList){
System.out.println(name);
}
}
}
OUTPUT
jre7_x64_setup.log
jre7_x86_setup.log

 

SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment