当我尝试从CSV文件的每一行读取一列
时,我在Java应用程序中会出现错误java.lang.ArrayIndexOutOfBoundsException: 1
我的代码就是这样使用opencsv
public void insertOjd(String fichierEntree) throws SQLException {
try {
CSVReader reader = new CSVReader(new FileReader(fichierEntree));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine != null) {
System.out.println(nextLine[1]);
}}....
它可能是CSV中的空行或评论行。错误意味着该行上没有第二个值(NextLine [1]是第二个值)。检查您的文件并打印Nextline [0],您会看到错误。NextLine [0]将包含整个行。确保您告诉OpenCSV使用Poper分离器,逃脱字符等。