C#无法写入文件("被其他进程使用")?

Jam*_*mes 3 c# exception file

我希望有人可以向我解释为什么会发生这种情况:)

当我使用下面的代码时,它给出了错误"进程无法访问文件'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)

MyK*_*SKI 6

在写入之前关闭文本文件.(不在代码中......物理关闭文本文件)