第一种:
/// <summary> /// 向txt文件写入内容 /// </summary> /// <param name="path">txt文件保存的路径,没有就创建,有内容就覆盖。例:"E:\text.txt"</param> /// <param name="contentSrt">要写入的内容</param> private void WriteForTxt(string path,string contentSrt) { FileStream fs = new FileStream(path, FileMode.Append); StreamWriter wr = null; wr = new StreamWriter(fs); wr.WriteLine(contentSrt); wr.Close(); }