Fork me on GitHub

C# 读取gb2312文本乱码

'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();

 

posted @ 2023-05-07 15:12  都一样*  阅读(438)  评论(0编辑  收藏  举报