C#  文本文件 ANSI编码格式 转 UTF8

如果用 Encoding.Convert()把ANSI格式的字节数组转成 UTF8格式的字节数组,然后用FileStream 去wirte字节数组,其结果为丢BOM,即保存为 UTF8 without BOM。

解决方法,用 StreamWriter,直接wirte string 即可。

                        using (StreamWriter fs = new StreamWriter(tmpPath + "info.txt", false, Encoding.UTF8))
                        {
                            fs.Write(string.Format("{0}\r\n{1}", txt, string.Join("\r\n", info)));
                            fs.Flush();
                            fs.Close();
                        }

 

 

相关文章:

  • 2021-12-24
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2021-08-10
  • 2021-12-13
  • 2022-12-23
  • 2021-09-14
  • 2021-12-26
相关资源
相似解决方案