List all the contents of a directory
The list method of File class can be used for listing all the contents of a directory.
import java.io.File;
/**
* File class examples
*/
public class FileExample {
public static void main(String[] args){
// Create file object representing the directory
File file = new File("d:\\temp");
// List the contents of the directory.
String contents[] = file.list();
// Loop through the array and display the file/directory names.
for (int i = 0; i < contents.length; i++) {
System.out.println(contents[i]);
}
}
}
Tags: File, file class examples, File examples, java.io, java.io.File
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply