c#写出文本保存到文件稳定代码
/// <summary> /// 写出文本 /// </summary> /// <param name="str">写出文本</param> /// <param name="file">文件名</param> public void write(string str, string file) { FileStream fs = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + file, FileMode.Create); StreamWriter sw = new StreamWriter(fs); //开始写入 sw.Write(str); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); }