Hello
My recursive file scan is not doing what I want it to do.
I want it to be able to go through all roots (drives)...
With no user intervention, so without including "C:\\" or "." as a string in the source, or without a TextIO.java class.
import java.io.*;
import java.util.*;
public class RecursiveFileListAttemp1 {
public static void main(String[] args) {
File f = new File("C:\\");
search(f);
}
public static void search(File f) {
if ( !f.exists() ) return;
String name = f.getName();
if ( f.isDirectory() ) {
File[] files = f.listFiles();
for( int i = 0 ; i < files.length; i++ ) {
search( files[i] );
}
}
}
}
At the moment I just get a null pointer exception...
I dont understand where Ive gone wrong in the code:
if its a file --> return the file name --> if its a directory --> list the files in the directory
Help please!