I have data in the below format
PAL : PAL : NF : "INCOME"."Taxable"
PAL : PAL : NF : "EXPENSES"."TotalExpenses"
PAL : PAL : NF : "EXPENSES"."Exceptional"
In java, i just want to delimit the data without doing any formatting, in the outputs also quotes should come. I usually use Univocity, when using the below code,
//Simple CSV File Read
List<String[]> allRows;
try {
CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setLineSeparator("\n");
settings.getFormat().setDelimiter(':');
CsvParser parser = new CsvParser(settings);
allRows = parser.parseAll(new FileReader(new File(csvFile)));
int i =0, cols=0;
for(String[] str:allRows){
i++;
cols = str.length;
for(String s:str)
System.out.print(s+" == ");
System.out.println("");
if(i == 10) break;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Output was like below, period symbol is within quotes, i am expecting output to be like input, quotes should come.
PAL == PAL == NF == INCOME"."Taxable
PAL == PAL == NF == EXPENSES"."TotalExpenses
PAL == PAL == NF == EXPENSES"."Exceptional
Expected Output
PAL == PAL == NF == "INCOME"."Taxable"
PAL == PAL == NF == "EXPENSES"."TotalExpenses"
PAL == PAL == NF == "EXPENSES"."Exceptional"
Author of the library here. The thing is that
"INCOME"."Taxable"is being handled as a quoted value, and it is treating the quotes betweenINCOMEandTaxableas unescaped quotes.It will basically try to "rescue" the value and find either a closing quote or a delimiter (determined by
settings.setUnescapedQuoteHandling(...)).In your case the easiest thing to do is to set your quote character to something like
'or even\0if your input doesn't have to handle quoted values anyway. With this you should get"INCOME"."Taxable"as you expect.Hope this helps