I am stuck in a situation where I am getting a file in byte[] which have comma separated values in quotes, I want to save it as CSV file and then read this file.
Sample data I am getting through byte[]:
"hi","how,are","you","what is","this"
"hi","how are","you","what is","this"
"hi","how,are","you","what, is","this"
Following is my code for saving it in CSV format.
byte[] bytes = myByteStream.getFile();
OutputStream out22 = new FileOutputStream("path/to/file/dummy.csv");
out22.write(bytes);
out22.close();
And the following code to read this CSV file.
CSVReader reader = new CSVReader(new FileReader("path/to/file/dummy.csv"), ',');
String[] nextLine;
while ((nextLine = reader.readNext()) != null)
{
System.out.println(nextLine[1]);
}
The problem I am facing is with the values that have comma in quotes, and strange thing is when I open that csv file and then "Save As" with csv and run the above code to read it, then CSVReader reads the files properly.
So I think that problem is in saving the file as csv. It is not properly saving the file in CSV format.
Any help, on how to save it in proper CSV format ?