I have been writing a program that ( so far ) sorts out all the sub directories inside of the same directory were the .jar file is executed .
Unexpected behavior has popped up unfortunately.
These undesired behaviors are as follows:
1: When testing this in Eclipse I get a list of the files inside of the package
2: After compiling the .jar file, I get null pointers errors when executing the program .
What am I doing wrong here, and how to correct it ?
public class Files {
File rawFiles;
List <File> fileList;
List <File> dirList;
List <File> outGoing;
String temp[];
Scanner scan;
public Files() throws Exception{
String x = Files.class.getProtectionDomain().getCodeSource().getLocation().getPath(); // get path were .jar is
String path = URLDecoder.decode(x, "UTF-8");
scan = new Scanner(System.in);
rawFiles = new File(path);
fileList = new ArrayList<File>( );
dirList = new ArrayList<File>();
outGoing = new ArrayList<File>();
fileList = (Arrays.asList(rawFiles.listFiles() ) );
for ( int i = 0; i != fileList.size(); i ++ ){ // build list of all directories
if (fileList.get(i).isDirectory() ){
dirList.add(fileList.get(i) );
}
} // End of for
for ( int i = 0; i != dirList.size(); i ++){ // filter out empty directories
temp = dirList.get(i).list(); // dirList.get(i).length DOES NOT WORK !!!
if ( temp.length > 0){
System.out.println("Added directory to processing list: " + dirList.get(i).getName() );
outGoing.add(dirList.get(i));
}
else{
System.out.println("Removed empty directory from list: " + dirList.get(i).getName() );
}
} // End of for
scan.nextLine(); // pause execution before closing
}
}