I am trying to read numbers from an excel file and putting them in arrays but I am getting an out of bounds exception ... the excel file has 2 columns and 32 rows per column... the numbers in the first column(which are 5 digits long) are to be inserted in an array named allInputs while those of the second column (3 digits long) are to be inserted in an array named allTargets ... the following is my code;
String[] allInputs = new String[32];
String[] allTargets= new String[32];
//Read the values from csv file
//Input file which needs to be parsed
String fileToParse = "C:\\Users\\ROBMARYAN\\Documents\\UOM\\Bsc IT Comp & Business\\3rd Yr\\Business Intelligence\\NeuralNetAssignment\\src\\inputs.csv";
BufferedReader fileReader = null;
//Delimiter used in CSV file
final String DELIMITER = ",";
try
{
String line = "";
//Create the file reader
fileReader = new BufferedReader(new FileReader(fileToParse));
//Read the file line by line
int icount=0; //determine where to store the input
int tcount=0; //determine where to store the target
while ((line = fileReader.readLine()) != null)
{
//Get all tokens available in line
String[] tokens = line.split(DELIMITER);
for(String token : tokens)
{
//Print all tokens
if (token.length() == 5)
{
***allInputs[icount]=token***;
System.out.println("Stored in all inputs:"+allInputs[icount]);
icount++;
}
else
{
allTargets[tcount]=token;
System.out.println("Stored in all targets:"+allTargets[tcount]);
tcount++;
}
System.out.println("iCOUNT:"+icount);
System.out.println("tCOUNT:"+icount);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
on the line where allInputs[icount]=token , I am getting the following error;
java.lang.ArrayIndexOutOfBoundsException: 32
Thanks in advance!