I am trying to read an Excel file but I cant seem to get my code to work. The error it returns has to with Array out of bounds, but whatever number It doesnt work. Any clue where my code is incorrect?
Notes: Trying to read only the Price column and make sure the values are not NULL, N/A, less than 80 and greater than 130.
SpreadSheet:
boolean flag = true;
File inputF = new File("data.xlsx")
InputStream getStream = new FileInputStream(inputF);
try{
if(getStream.read() != -1){
BufferedReader reader = new BufferedReader(new InputStreamReader(getStream));
String line;
while((line = reader.readLine()) != null){
String[] csvs = line.split(",");
for (String str : csvs){
if (str != null && (str.equals("NA") || str.length() == 0)) {
System.out.println(str);
flag = false;
break;
}
}
if (!flag){
break;
}else{
String Price = csvs[1]; //TODO replace with price index
price = price.trim();
Integer priceValue = new Integer(Price);
if (priceValue != null && (priceValue < 80 || priceValue > 130)){
flag = true;
}
}
}
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(flag);
return flag;
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
Expected Output: (Based on spreadsheet provided)
True