string filename="d:\\a.txt";
System.IO.File.Create(filename);
System.IO.StreamWriter sw=System.IO.File.AppendText(filename);
sw.WriteLine("asfsdfs");
sw.Close();
目的是建一个文件,往文件中写入以上内容,但是报错,说别一个文件在使用,不知道如何解决。
System.IO.File.Create(filename);
System.IO.StreamWriter sw=System.IO.File.AppendText(filename);
sw.WriteLine("asfsdfs");
sw.Close();
目的是建一个文件,往文件中写入以上内容,但是报错,说别一个文件在使用,不知道如何解决。
System.IO.FileStream file = System.IO.File.Create(filename);
file.Close();
System.IO.StreamWriter sw=System.IO.File.AppendText(filename);
sw.WriteLine("asfsdfs");
sw.Close();如上即可,Create方法返回FileStream类型值,由于你没有接收操作返回值,所以文件一直处于打开没有关闭状态,你接着再打开此文件就会报错了