Read all files and filenames in a folder using java

by THavamani 2013-08-27 18:54:44

I want to read all the files and file names in a folder through Java

public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}

final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);

Tagged in:

970
like
0
dislike
0
mail
flag

You must LOGIN to add comments