我需要做的是将字符串写入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) 我希望有人可以向我解释为什么会发生这种情况:)
当我使用下面的代码时,它给出了错误"进程无法访问文件'C:\ test.txt',因为它正被另一个进程使用."
我对C#很新,所以我不确定是怎么回事,提前谢谢!
String fileNameBefore = @"C:\\test.txt";
public void output(String hex)
{
using (StreamWriter writer = new StreamWriter(fileNameBefore, true))
{
writer.Write(hex);
writer.Close();
}
}
Run Code Online (Sandbox Code Playgroud)