C#中将文件保存为utf-8无bom格式 UTF8Encoding(false)
分类:.Net知识问答| 发布:佚名| 查看:1747 | 发表时间:2014/6/12
在讲魅族M9的通讯录导出为xml格式之后, 又转换成vCard(.vcf),导出的名片后,在红米手机里无法导入,提示格式不对,最后发现,原来红米手机不支持utf8+BOM编码的名片导入。

因此,修改了c#转换导出的编码:
04 | /// <param name="Shtml">要写入的内容</param> |
05 | /// <param name="TemplatePath">存储路径</param> |
06 | /// <returns></returns> |
07 | public static void WriteHtmlFile( string Shtml, string HtmlPath) |
09 | StreamWriter sw = null ; |
12 | UTF8Encoding utf8 = new UTF8Encoding( false ); |
13 | using (sw = new StreamWriter(HtmlPath, false , utf8)) |
20 | throw new Exception( "存储路径错误,请检查路径" + HtmlPath + "是否存在!" ); |
关于UTF8 与 UTF8 +BOM 区别