This is my code:
CSVReader reader = new CSVReader(isReader);
while ((col = reader.readNext()) != null) {
String c1 = col[1];
}
this is my csv file:
"a","","c"
"1",,"3"
Is there a way I can differentiate between null and ""? OpenCSV seems to treat everything as non-null String. Can I tell it to treat empty fields as null?
Adding to @Gavriel's answer, starting from OpenCSV 3.6 (maybe earlier), I found that strictQuotes doesn't help with returning null anymore.
CSVReaderBuilder has withFieldAsNull() for this purpose.
CSVReader csvReader = new CSVReaderBuilder(csvFileReader)
.withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS)
.build();
It is not possible. There is no difference between an empty string and the java specific null
in the CSV
format's philosophy. The null
is an empty reference in the java
object memory model. In CSV there aren't any references, but only empty values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With