Question

I am writing a CSV parts.Its easy to write it using java

String s = null
while( (s= bufferedReadr.readLine() !=null){
  String parts[] = s.split(',');
  //process parts
}

The problem is data is in format
"a", "b","c","d","e","f".

But some of the data is
"a" ,",b" ,"c",",a","e","f" .

EDIT

The thing is i get one line of CSV input from some other code which i cant change.

SO i get each line which is in CSV format. And i want to split that.I cant use csvlibs as they parse whole file and requie a handle to file.

some quote are present withing data parts which is causing problem.

How do i resolve this?Any open src libs i can use?

Was it helpful?

Solution

Do not split data yourself. Use one of available libraries that do this job well. For example take a look on opencsv.

OTHER TIPS

As the other comments say, use OpenCSV. There is the CSVReadr class with this contructor

public CSVReader(Reader reader, char separator, char quotechar)
And methods like readAll(), readNext(), .... About the Reader, there are many different options:.., InputStreamReader, StringReader

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top