我正在尝试使用带有UTF8编码的VB.Net创建一个文本文件,没有BOM.任何人都可以帮助我,怎么做?
我可以用UTF8编码写文件但是,如何从中删除字节顺序标记?
edit1:我尝试过像这样的代码;
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()
Run Code Online (Sandbox Code Playgroud)
1.html仅使用UTF8编码创建,2.html使用ANSI编码格式创建.
简化方法 - http://whatilearnttuday.blogspot.com/2011/10/write-text-files-without-byte-order.html