0
在我的小控制台应用程序的c#我必须写入一个文件,如果它不是我必须创建它。它工作正常,当文件已经创建,但是当我尝试创建文件然后写入它我得到一个System.IO.IOException说该文件正在别处使用。这里是我一直在使用创建然后写入文件c#
if (!File.Exists(FilePath))
{
File.Create(FilePath);
}
FileInfo file = new FileInfo(FilePath);
using (TextWriter tw = new StreamWriter(file.Open(FileMode.Truncate)))
{
tw.Write(filePresent);
tw.Close();
}