c# 自动识别文件编码
安装nuget【Ude.NetStandard】
using (FileStream fs = File.OpenRead(ParseFilePath))
{
Ude.CharsetDetector cdet = new Ude.CharsetDetector();
cdet.Feed(fs);
cdet.DataEnd();
if (cdet.Charset != null)
{
//Debug.WriteLine("Charset: {0}, confidence: {1}",
// cdet.Charset, cdet.Confidence);
encoding = Encoding.GetEncoding(cdet.Charset);
}
else
{
Console.WriteLine($"无法识别文件编码:{ParseFilePath}");
return;
}
}
留待后查,同时方便他人
联系我:renhanlinbsl@163.com
联系我:renhanlinbsl@163.com