C#文件写入问题!
请各位路过的大哥帮忙看看下面一小段代码!为什么 "C " 里面的字符串不能写入Log4.
最后输出结果是Log4.txt而不是C字符里面的内容呢!
string C = "ASAS\nsdfdfsd\nsadasd ";
string F = "Log4.txt ";
string STR;
StreamWriter sr = File.CreateText(F);
sr.WriteLine(C);
StreamReader sr1 = new StreamReader(F);
STR = sr1.ReadLine();
while (STR != null)
{
Console.WriteLine(F);
STR = sr1.ReadLine();
}
------解决方案--------------------sr.WriteLine(C);
sr.Close();//sr.Flush(); 添加此段代码
StreamReader sr1 = new StreamReader(F);