I am trying to read a big csv file in a while loop.
But when I run the code I got java.lang.ArrayIndexOutOfBoundsException: 5
Is there a step I am missing?
String csvFileToRead = "C:/automation/test.csv";
BufferedReader br = null;
String line = "";
String splitBy = ",";
try { boolean firstLine = true;
br = new BufferedReader(new FileReader(csvFileToRead));
while ((line = br.readLine()) != null ) {
if (firstLine) {
firstLine = false;
continue;}
String[] id = line.split(splitBy);
String replace = id[5].replace("\"", "");
String cardNo = id[5].replace("\"", "");
String fname = id[8].replace("\"", "");
String name = driver.findElement(By.id("bnxczxc")).getAttribute("value");
if (name.equals(fname)) {
//code
}
else {
//code
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
}
catch (IOException e) {
e.printStackTrace();}}}