My Text file is below. The bounds should be 0-2 for letter A or D then 2-15 for StateName(these are new states being added to a stack) and 15-25 for what should be the capital, but not all of them have capitals and for those I am getting an out of bounds exception is there a way around this or to tell it to stop then go to the next line when it might detect it out of bounds without a try catch.
D Pennsylvania
D PA
A PuertoRico San Juan
A Maine Augusta
D Tennessee
D Franklin
A Alabama Montgomery
A Thailand Bangkok
My code is
public void loadStacks(String filename) throws IOException
{
FileInputStream fis1 = new FileInputStream("UpdateStacks.txt");
//obtains file statearray.txt
BufferedReader br1 = new BufferedReader(new InputStreamReader(fis1));
//reads statearray.txt
String stackLetter, stateName, stateCapital;
String inputString;
inputString = br1.readLine();
while (inputString != null)
//while loop to continually create state objects
{
stackLetter = inputString.substring(0, 2).trim();
//parses the file for Stack Letter A or D which is add or delete
stateName = inputString.substring(2, 14).trim();
//parses the file for state name
stateCapital = inputString.substring(14, 15).trim();
//parses the file for state capital
if(stackLetter.equals("D"))
deleteStack.push(
new States(inputString.substring(1),"", "",0,"",0));
else
addStack.push(
new States(inputString.substring(1),"", "",0,"",0));
inputString = br1.readLine();
} // end while (inputString != null)
br1.close();
}//end loadData(String filename) throws IOException