'Using BufferedReader to print out data separated by commas
I need to print out values from certain columns in a csv file.
Below is an example of the data. There is a comma in one field and I have tried putting in the commas like; System.out.println("\"" + b[0] + "\",\"" +b[4] + "\",\""+ b[6] + "\""); But this confuses the code and mixes up the commas within the csv file value.
Code looks like this;
"Van","Truck",""Car"," new""
I want to display the data like this:
"Car,new", "Van", "Truck"
Note the comma at the end of Car
Below is my code. How can I get it to ignore print out and ignore the comma after Car instead of putting double quotes around it?
thanks in advance
BufferedReader br = new BufferedReader(new InputStreamReader(sr));
String splitBy = ",";
String line = br.readLine();
while((line = br.readLine()) != null){
String[] b = line.split(splitBy);
System.out.println("\"" + b[0] + "\",\"" +b[4] + "\",\""+ b[6] + "\"");
}
br.close();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

