0

I have a csv list like this:

abc;def;ghi;
jkl;mno;p;
qrs;tuv;wxy;
z;zz;zzz;

When parsing with opencsv like this:

CSVReader reader = new CSVReader(new FileReader("tmplist.csv"));
String[] nextLine;
int lineNumber = 0;
while ((nextLine = reader.readNext()) != null) {
    lineNumber++;
    System.out.println("Line # " + lineNumber);

    // nextLine[] is an array of values from the line  // no it's not
    System.out.println(nextLine[0]);
}

I get the following result:

Line # 1

abc;def;ghi;

Line # 2

jkl;mno;p;

Line # 3

qrs;tuv;wxy;

Line # 4

z;zz;zzz;

How can I get it to work like it is supposed to, i.e. the values in each line are separated in the nextLine[] array ?

JoachimR
  • 5,150
  • 7
  • 45
  • 50

1 Answers1

3

CSVReader uses the default comma , character when parsing CSV files. Use the constructor that specifies the separator character instead:

CSVReader reader = new CSVReader(new FileReader("aaa.txt"), ';');
Reimeus
  • 158,255
  • 15
  • 216
  • 276