Reads in simple addresses from a user specified file.
@author
@version
import java.util.Scanner;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
public class AddressParser{
public static void main( String[] args ){
Scanner stdinScanner = new Scanner( System.in );
String filename;
Scanner addressScanner = null;
String firstName;
String lastName;
int streetNumber;
String streetStr;
String city;
String state;
int zipCode;
try{
System.out.print("Please enter the output filename: ");
filename = stdinScanner.next();
addressScanner = new Scanner( new FileReader( filename ) );
while( addressScanner.hasNext() ){
firstName = addressScanner.next();
lastName = addressScanner.next();
streetNumber = addressScanner.nextInt();
streetStr = addressScanner.nextLine();
city = addressScanner.next();
state = addressScanner.next();
zipCode = addressScanner.nextInt();
System.out.println("Found address: \"" + firstName + " " + lastName + ", "
+ streetNumber + streetStr + ", " + city + " "
+ state + " " + zipCode + "\"");
}
}catch( FileNotFoundException e ){
System.err.println("Sorry, that was not a valid filename: " + e.getMessage() );
return;
}catch( InputMismatchException e){
System.err.println("Error, unable to parse input!" );
return;
}catch( Exception e){
System.err.println("ERROR: " + e.getMessage() );
return;
}finally{
if( addressScanner != null ){
addressScanner.close();
}
}
}
}