JoachimR
JoachimR

Reputation: 5258

opencsv values of one line are not separated

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 ?

Upvotes: 0

Views: 185

Answers (1)

Reimeus
Reimeus

Reputation: 159864

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"), ';');

Upvotes: 3

Related Questions