I am reading a csv file and then writing it to other file with additional column, when I am moving the data from a list to the additional column I got IndexOutOfBounds
private void writeDataToCSVDestinationFile(Path csvPath, Path destPath, String colToNormalize) throws IOException, CsvException {
CSVWriter writer = new CSVWriter(new FileWriter(destPath.toString()));
CSVReader reader = new CSVReader(new FileReader(csvPath.toString()));
String [] headerDes = new String [header.length+1];
for (int i=0; i<header.length; i++){
headerDes[i]= header[i];
}
headerDes[header.length]= colToNormalize+"_scaled";
writer.writeNext(headerDes);
String[] eachLineInTheOriginalFile;
String[] lineToBeWritten = new String[headerDes.length];
int j =0;
while ((eachLineInTheOriginalFile=reader.readNext())!=null){
for (int i =0; i<eachLineInTheOriginalFile.length; i++ ){
lineToBeWritten[i] = eachLineInTheOriginalFile[i];
}
lineToBeWritten[eachLineInTheOriginalFile.length]=dataAfterNormalization.get(j).toString(); //the line generate the exception
j++;
}
writer.writeNext(lineToBeWritten);
}
Any one can help me to solve it.