我正在尝试使用VB.Net创建一个UTF8编码的文本文件,但不带BOM。有人能帮助我如何做到这一点吗?
我可以使用UTF8编码写入文件,但是如何删除其中的字节顺序标记?
编辑1: 我已经尝试了类似这样的代码;
Dim utf8 As New UTF8Encoding()
Dim utf8EmitBOM As New UTF8Encoding(True)
Dim strW As New StreamWriter("c:\temp\bom\1.html", True, utf8EmitBOM)
strW.Write(utf8EmitBOM.GetPreamble())
strW.WriteLine("hi there")
strW.Close()
Dim strw2 As New StreamWriter("c:\temp\bom\2.html", True, utf8)
strw2.Write(utf8.GetPreamble())
strw2.WriteLine("hi there")
strw2.Close()
1.html文件只能使用UTF8编码创建,而2.html文件则是使用ANSI编码格式创建。
简化方法 - http://whatilearnttuday.blogspot.com/2011/10/write-text-files-without-byte-order.html