I have a CSV file which I have to read through my code. Now if I read the file line by line and store each line as a String using the String.split(","); function, I face a problem that at some places the the data itself contains ",". So the split doesn't work properly.
Depending on the source, your CSV file may have quotes around all strings and no quotes around numbers, or quotes around strings that contain commas. Try to create some with quotes in the values, too, just to see how they are handled. Here's something I got from Excel:
It did not quote the number. It did not quote a simple string. It quoted a string with a comma in it. It quoted the string with quotes in it, doubled the quotes I entered, and warned me that it might not be DOS CSV compatible. Maybe you'll get lucky and won't have to implement that one!
So without the escaped quotes:
With the escaped quotes you'd take to the next quote, skip it and if there is another quote or a comma next. Lemme know if it's not clear how "skip" and "take" translate into Java substringing or array copying.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi