I am trying to recursively search the directory and list all .txt files found. This is my code for it:
private static void listFilesForFolder(File folder) throws FileNotFoundException {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(Arrays.toString(fileEntry.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(".txt");
}
})));
}
}
}
I'm using FileFilter to print out all the .txt files but it prints out null instead. Anyone know why that's the case?