Example & Tutorial understanding programming in easy ways.

How to get list of all files from a folder in java?.

This is a basic algorithm, but it can be very useful in some situations and very handy for those that are learning Java.

A Java program which can list all files in a given directory,In this code you can list all files in a given directory:

Example:

import java.io.File;

public class ListFilestest

{

public static void main(String[] args)

{

// Directory path here

String path = "c\javatest\abc.txt";

String files;

File folder = new File(path);

File[] listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++)

{

if (listOfFiles[i].isFile())

{

files = listOfFiles[i].getName();

System.out.println(files);

}}}

Read More →