C# 读取gb2312文本乱码

发布时间 2023-05-07 15:20:30作者: 都一样*

'gb2312' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider meth...

 

    string Path = @"E:\SQLQuery.sql";
    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);// 使用了gb2312 需要定义
    StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("gb2312"));
    //sr.ReadToEnd().Dump();
    Console.WriteLine(sr.ReadToEnd());
    sr.Close();