写入包含逗号的CSV

Jam*_*mes 3 java csv

我需要做的是将字符串写入CSV文件,问题是某些字符串包含一个,将字符串分成两半的字符串.所以我正在尝试将下面的字符串"fileInfo"发送到CSV,但正如我所说,它有时包含一个,.有没有人知道如何解决这个问题,因为我会非常感激!

public class FileOutput {
  public void FileOutputToFile(String hex) throws Exception{
    String fileInfo = hex;
    try {
      PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.csv", true)));
      out.print(fileInfo);
      out.close();
    }catch (IOException e){
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*erg 9

您可以更改分隔符或在值周围加上引号.虽然,我建议使用诸如openCSV之类的CSV解析器来完成这项工作.