I want to store the string into CSV file using the following code but empty CSV is being generated.
Code
try {
PrintWriter writer = new PrintWriter(new File("test.csv"));
StringBuilder sb = new StringBuilder();
String str ="1 cup, honey, 2 tablespoons ,canola" ;
sb.append(str);
writer.write(String.valueOf(sb));
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
Expected Output :
The data should show like this in CSV file.
1 cup
honey
2 tablespoons
canola
How I could get expected results.?