//c#之如何转换文本文件编码格式为utf-8
string content = File.ReadAllText(path, Encoding.Default); File.WriteAllText(path, content, Encoding.UTF8);
//下面是C#在写文件时指定BOM头的代码:var utf8WithBom =
new
System.Text.UTF8Encoding(
true
);
// 用true来指定包含bom
//下面的代码是不需要BOM:var utf8WithoutBom =
new
System.Text.UTF8Encoding(
false
);
swr =
new
StreamWriter(
"okbase.txt"
,
false
, utf8WithBom);
swr.Write(
"hello okbase.net!"
);