java - read csv file with a delimiter specified in the value itself -
the below example record csv file seperated comma delimiter there chances when particular column has comma in-itself 1 below show in double quotes " " in csv file.
example csv file: column1, column2, "column, 3",-,1g9937
when try read file using java code @ third position prints column , not column, 3 how can tackle such cases ?
string cvssplitby = ","; try { br = new bufferedreader(new filereader(csvfile)); while ((line = br.readline()) != null) { // use comma separator string[] businessdirection = line.split(cvssplitby); system.out.println("funcvp = " + businessdirection[0] + " , vp=" + businessdirection[1] + " , vp=" + businessdirection[2]+ " , vp=" + businessdirection[3] + " , vp=" + businessdirection[4]+ " , vp=" + businessdirection[5]);
you cannot use split parse csv file. can use library (e.g. supercsv or opencsv) or have follow csv format rules. instance, here should ignore delimiter (i.e. comma) between double quotes (you can use regex this).
Comments
Post a Comment