Consider this standard directory traversal code:
static void walk(File f) throws IOException{
System.out.println(f.getPath());
if(f.isFile()) return; // leaf
File[] subs = f.listFiles(); // If it aint a file, it's a directory. Right?
if(subs == null) return; // returns null at some point
for(File subDir : subs){
walk(subDir.getAbsoluteFile());
}
}
If I execute it on the following directory structure: c:\ -> Folder1 -> Folder2 (=a symbolic link to c:\Folder1)
, at some point f.listFiles()
returns null
. From the documentation, listFiles
Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
Clearly, the path denotes a directory. This probably means an I/O error occurs. But what is the error itself?