ZIPCODE, CITY, STATE, LATITUDE, LONGITUDE
ZIPCODE, CITY, STATE, LATITUDE, LONGITUDE
I'm trying to make this able to open a text file with addresses formatted as such, Create a loop that instantiates a new ZipCode object with the five perameters in order, and then adds that object to ArrayList myZips.
I have a feeling that at least my delimiters are wrong.
public void readZipCodeData(String filename){
Scanner inFS = null;
FileInputStream fileByteStream = null;
try{
// open the File and set delimiters
fileByteStream = new FileInputStream(filename);
inFS = new Scanner(fileByteStream);
inFS.useDelimiter(", *");
// continue while there is more data to read
while(inFS.hasNext()) {
// read five data elements
int zipCode = inFS.nextInt();
String city = inFS.next();
String state = inFS.next();
double latitude = inFS.nextDouble();
double longitude = inFS.nextDouble();
ZipCode z1 = new ZipCode(zipCode, city, state, latitude, longitude);
myZips.add(z1);
}
fileByteStream.close();
// Could not find file
}catch(FileNotFoundException error1) {
System.out.println("Failed to read the data file: " + filename);
// error while reading the file
}catch(IOException error2) {
System.out.println("Oops! Error related to: " + filename);
}
}
Everytime I try running it as is it gives me a
java.util.InputMismatchException:
null (in java.util.Scanner) error on the double longitude line. Any ideas?