我需要创建/附加一个文本文件并在其中写入一些数据。当我将下面的代码写入我的ASP.NET应用程序时,它会给出错误提示:文件正在被另一个进程使用。
if (!File.Exists(path\file))
File.CreateText(path\file);
using(StreamWriter sw = File.AppendText(Server.MapPath(path\file)))
{
sw.WriteLine("Text Data");
sw.Close();
}
sw.Close()
不是必要的,因为你已经将 StreamWriter 放在 using 块中。 - Tim