我希望有人能向我解释为什么会这样 :)
当我使用下面的代码时,出现错误“该进程无法访问文件 '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();
}
}
最佳答案
写入前关闭文本文件。 (不在代码中...物理关闭文本文件)
关于C# 无法写入文件 ("being used by another process")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9086706/