I have this CSV with this format, I need to split in 16 Parts, according with the text's:
"MY TEXT","EVER, OK",,,,,,,,,,"The, CARLO","DO","ALFA","OME, GA",,
I have this way, but when appear case's with commas inside "OME, GA" doesn't work.
String[] lineToMap = line.split(",");
How I can control this cases?
Solution
I discovered this library: OPEN CSV, in my Test's work very well, but I have a problem with the codification (strange symbols like � instead ü), with characters like ü, ö, etc.. I'm using languages like German and French. I was testing with UTF-8 but didn't work, Any idea to fix this?
CSVReader reader=new CSVReader(new InputStreamReader(new FileInputStream("data/test.csv"), "UTF-8"),
',', '"', 0);
//Read CSV line by line and use the string array as you want
String[] nextLine;
try {
while ((nextLine = reader.readNext()) != null) {
if (nextLine != null) {
for (String element : nextLine) {
System.out.println(element);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}