gpt4 book ai didi

java - 使用 java.arraycopy 时遇到问题。 (ArrayIndexOutofBounds)

转载 作者:行者123 更新时间:2023-11-29 05:49:16 24 4
gpt4 key购买 nike

我正在尝试读取一个 csv 文件并将其数据复制到一个数组中。我似乎无法让它以这种方式工作,我也不确定为什么。

String[] row = new String[0];
ArrayList<String[]> csv = new ArrayList<>();

String parser = "SPImages";
CSVReader reader = new CSVReader(new FileReader("C://data.csv"));
String[] nextLine;


while ((nextLine = reader.readNext()) != null){
System.arraycopy(nextLine, 0, row, 0, nextLine.length);
}

最佳答案

很可能目标数组(在本例中为“行”)不如源数组(在本例中为“nextLine”)大。与列表不同,数组不会自动调整大小。

关于java - 使用 java.arraycopy 时遇到问题。 (ArrayIndexOutofBounds),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14614285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com