1、将txt内容清空 [html] view plain copy public void ClearTxt(String txtPath) { String appDir = System.AppDomain.CurrentDomain.BaseDirectory + @"Txt\" + txtPath; FileStream stream = File.Open(appDir, FileMode.OpenOrCreate, FileAccess.Write); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); stream.Close(); } 2、向txt中追加内容 [html] view plain copy public void SaveFile(string str,String txtPath,bool saOrAp) { String appDir = System.AppDomain.CurrentDomain.BaseDirectory + @"Txt\" + txtPath; StreamWriter sw = new StreamWriter(appDir, saOrAp);//saOrAp表示覆盖或者是追加 sw.WriteLine(str); sw.Close(); }