I am using OpenCSV.
I have a CSVReader
trying to parse a CSV file.
That file has quote char \"
and separator char ,
an
The CSVReader
is not fully RFC4180 compliant. Use their newer CSV reader (RFC4180Parser):
RFC4180Parser rfc4180Parser = new RFC4180ParserBuilder().build();
CSVReaderBuilder csvReaderBuilder = new CSVReaderBuilder(
new FileReader("input.csv"));
CSVReader reader = csvReaderBuilder
.withCSVParser(rfc4180Parser)
.build();
To read a String line formatted as a CSV:
String test = "ballet 24\"\" classes";
String[] columns = new RFC4180Parser().parseLine(test);
To use the reader (an alternative is reader.readNext()
):
for (String[] line : reader.readAll()) {
for (String s : line) {
System.out.println(s);
}
}
See http://opencsv.sourceforge.net/#rfc4180parser for more details.
Code taken from GeekPrompt