开发者_如何学运维What I need to do is write strings to a CSV file, the problem is some string contain a ,
which will separate the string in half. So I'm trying to send the string "fileInfo" below to the CSV but as I said it sometimes contains a ,
. Does any one know how to solve this as I would be most greatful!
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){
}
}
}
You can change delimiter or put quotation marks around the values. Although, I recommend using a CSV parser such as openCSV which will do the job for you.
Another implementation I was happy with: Apache Commons CSV.
The openCSV does also a good job.
精彩评论