我在将文本打印到.csv文件时遇到问题。我的字符串中有一个逗号,我最终将其打印到两个单元而不是一个单元中。这是代码:
String companyName1 = "Edison Corporation, LLC co";
String profit1 = "$100";
String fileName = "Result.csv";
File file = new File(fileName);
output = new PrintWriter(file);
output.println(companyName+","+profit);
//This gives me the following:
// Edison Corporation LLC co $100
//I need:
// Edison Corporation, LLC co $100
最佳答案
CSV格式允许带逗号的字符串,但是必须将其用双引号引起来。尝试这个:
output.println("\""+companyName+"\","+profit);
关于java - 如何使用Java中的PrintWriter将逗号打印到.csv文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15856879/