C# bom头清理 工具方法
public bool clean(string path)
{
byte[] bs = File.ReadAllBytes(path);
byte[] bomBuffer = new byte[] {
0xef, 0xbb, 0xbf };
if (bs.Length<=3)
{
return false;
}
if (bs[0] == bomBuffer[0]
&& bs[1] == bomBuffer[1]
&& bs[2] == bomBuffer[2])
{
using (var sink = new StreamWriter(path, false, new System.Text.UTF8Encoding(false)))
{
sink.Write(new UTF8Encoding(false).GetString(bs, 3, bs.Length - 3));
}
}
return false;
}