当我将数据从列表移动到我得到的附加列时,我正在读取一个csv文件,然后将其写入另一个带有附加列的文件 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);
}
任何人都可以帮我解决这个问题。
1条答案
按热度按时间pw9qyyiw1#
没有索引
j
在dataafternormalization中,因此get会抛出该错误。在这方面你还有另一个问题。要编写的行的最终索引为
eachLineInTheOriginalFile.length - 1