Listing the Files or sub-directories in a Directory

Submitted by:Jhon Smith

Date added:25 March, 2013

Category:Java

Java code for listing files or sub-directories in a directory

Tags: listing files

Code Snippet:

File dir = new File("directoryName");
String[] children = dir.list(); //can also take a FilenameFilter as argument

// This filter only returns directories
FileFilter fileFilter = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
 
 

Comments