Aaron Lemon
Aaron Lemon

Reputation: 25

Having trouble using java.arraycopy. (ArrayIndexOutofBounds)

I am trying to read a csv file and copy it's data into an array. I can't seem to get it to work this way and I'm not sure why.

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);
}

Upvotes: 1

Views: 111

Answers (1)

jfrank
jfrank

Reputation: 733

Most likely the destination array (in this case "row") is not as big as the source array (in this case "nextLine"). Arrays, unlike Lists, don't auto-resize.

Upvotes: 3

Related Questions