If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
I've been trying to figure this out but I just can't seem to get it working. My program searches through directories based on user input. When I was hard coding the directory I had no problem but I have now decided to use the Scanner class to accept user input and now I receive a null pointer exception. When the directories do not contain spaces I have no problem. I'll attach a copy of the code.
Thanks
hally
import java.io.File;
import java.util.*;
public class DirectoryLookup {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please enter directory: ");
File path = new File(input.next());
//File path = new File("C:\\Documents and Settings\\hally");
System.out.println(path);
File[] FilesInDir = path.listFiles();
if (FilesInDir.length == 0 ){
System.out.println("No Files exsits in "+path+" directory");
}
else {
for (int i=0; i<FilesInDir.length; i++) {
System.out.println(FilesInDir[i].getName().toString());