I tried your example. I get a null pointer when trying to open /root
. When I try to open it via terminal, it just says that I don't have the permissions.
So you basically have a problem with permissions.
The javadoc says :
̀Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
In order to catch this, you should check if filesInDirectory
is null.
public static void parseAllFiles(String parentDirectory){
File[] filesInDirectory = new File(parentDirectory).listFiles();
//Added this line.
if(filesInDirectory != null){
for(File f : filesInDirectory){
if(f.isDirectory()){
parseAllFiles(f.getAbsolutePath());
}
System.out.println("Current File -> " + f);
}
}
}