Listing the Files or Subdirectories in a Directory

Submitted by:Jhon Smith

Date added:25 April, 2013

Category:Java

Java code example to list the Files or Subdirectories in a Directory

Tags: list files , list subdirectories

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