About Bijoy

Bijoy has written 148 articles so far, you can find them below.

Listing Files in a Directory

If you are developing an application it is often required to list the files in a directory . The following code shows the way in which files can be listed in Java.

import java.io.*;

public class ListFiles {

public static void main(String[] args) {
File file = new File("E:/temp");
if (file.isDirectory()) {
for (File childFile : file.listFiles()) {
System.out.println("File Name :" + childFile.getName());
} else {
System.out.println("The path is not a directory");