Archives for 

File Handling

Basic file operations

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");
}
System.out.println("Finished");
}
}