我使用以下代码在*.txt
文件上写,但没有任何反应。甚至,也不例外。
FileStream fs = new FileStream(@"D:\file.txt",FileMode.OpenOrCreate,FileAccess.Write,FileShare.None); //Creating a stream with certain features to a file
StreamWriter writer = new StreamWriter(fs); //Use the fs to write
// writer.WriteLine(Text.Text); none of the following methods works
writer.Write("aaaaaaaaaaaa");
fs.Close();
由于
答案 0 :(得分:3)
尝试将其封装在这样的使用块中:
using ( FileStream fs = new FileStream(@"D:\file.txt",FileMode.OpenOrCreate,FileAccess.Write,FileShare.None))
using (StreamWriter fw = new StreamWriter(fs))
{
fw.Write("aaaaaaaaaaaa");
}
StreamWriter
在将数据写入基础流之前缓冲数据。您需要通过部署StreamWriter