import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class WriteCsv {
public static void main(String[] args) {
try (PrintWriter writer = new PrintWriter(new File("file.csv"))) {
StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append("id");
stringbuilder.append(',');
stringbuilder.append("Name");
stringbuilder.append('\n');
stringbuilder.append("1");
stringbuilder.append(',');
stringbuilder.append("Joe Root");
stringbuilder.append('\n');
writer.write(stringbuilder.toString());
System.out.println("done!");
} catch (FileNotFoundException exception) {
System.out.println(exception.getMessage());
}
}
}