HOME      BLOG       FORUMS      CONTACT       ABOUT

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]);
		}

	}
}

Share

Tags: , , , ,


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.

AddThis Social Bookmark Button

Leave a Reply