C#如在txt文件的末尾续写
using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(something);
}
注意,FileMode.Append表示是追加。
有专用的方法:静态类File.AppendAllText方法。
//第二个参数为true表示追加,false表示覆盖
StreamWriter sw = new StreamWriter("c:\test.txt", true);
sw.Write("AAAAAAAAAAAAA");
sw.WriteLine("BBBBBBBBBBBBBB");
using SYSTEM.IO;
//C#追加文件
StreamWriter sw=File.AppendText(Server.MapPath(".")+"\\myText.txt");
sw.WriteLine("追逐理想");
sw.WriteLine("kzlll");
sw.WriteLine(".NET笔记");
sw.Flush();
sw.Close();
StreamWriter sw=File.AppendText(System.Windows.Forms.Application.StartupPath+"\\lgcx.log");
sw.WriteLine(SysLog.FProgramName+SysLog.FCreateName+SysLog.FTime+SysLog.FId+SysLog.FPath+SysLog.FDesc);
//sw.WriteLine("kzlll1");
//sw.WriteLine(".NET笔记1");
sw.Flush();
sw.Close();