I'm trying to read a CSV file in my loading program.
As a CSV file, its data format is thus:
1,dataA,dataB,"String Data",dataD
2,dataA,dataB,"String Data",dataD
3,dataA,dataB,"String Data",dataD
Previously, I was using Files.newBufferedReader
to read my file line by line, which works. But it has come to my attention that some data can look like this:
1,dataA,dataB,"String Data",dataD
2,dataA,dataB,"String
Data",dataD
3,dataA,dataB,"String
Data",dataD
In some of my string data, there are potential line breaks.
I thought of removing the line breaks as per this suggestion, but that will affect the individual entries as well. And I don't think its recommended to manually remove the line breaks from the source data itself.
Is there any way to split so that I can still read it entry-by-entry but retain the line breaks only in the string data which is encapsulated by quotation ("") marks?
Edit
As per suggestion, I've been reading up on something called OpenCSV.
No, I am still getting java.lang.ArrayIndexOutOfBoundsException
due to the spacing.
It's still reading
3,dataA,dataB,"String
Data",dataD
for example as 3 lines as opposed to 1.
Edit 2
I stand corrected. OpenCSV worked; the error was because I was still calling the older method.