代码如下:
 1         /// <summary>
 2         /// 将数据保存为txt文件
 3         /// </summary>
 4         /// <param name="filename">txt文件名</param>
 5         /// <param name="Content">txt文件内容</param>
 6         public  void SaveDataToTxt(string filename,string Content)
 7         {
 8             // FileStream 添加引用 using System.IO; (此处是将文件保存到E盘)
 9             FileStream fs = new FileStream(@"E:\" + filename + ".txt", FileMode.OpenOrCreate, FileAccess.Write);
10             StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
11             //通过指定字符编码方式可以实现对汉字的支持,否则在用记事本打开查看会出现乱码
12             sw.Flush();
13             sw.BaseStream.Seek(0, SeekOrigin.Begin);
14             sw.WriteLine(Content);
15             sw.Flush();
16             sw.Close();
17         }

 

 

相关文章:

  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2021-09-08
  • 2021-11-17
猜你喜欢
  • 2021-09-08
  • 2021-12-05
  • 2022-12-23
  • 2021-08-17
  • 2021-09-25
  • 2021-12-11
  • 2021-11-04
相关资源
相似解决方案