zoukankan      html  css  js  c++  java
  • 读一个文本文件总是出现乱码怎么办

    可能的原因是你的文本文件的Encoding是gb2312的.而.Net 读文文件的缺省Encoding是UTF8
    所以最好的办法将其转换为utf8. 下面是代码片断
    while(true)
    {
    System.Windows.Forms.OpenFileDialog dialog 
    = new OpenFileDialog();
    dialog.Filter 
    = "cs file|*.cs|all file|*.*";
    dialog.Multiselect 
    = false;
    if(dialog.ShowDialog(this== DialogResult.OK)
    {
        string fileName = dialog.FileName;
        System.IO.StreamReader sr 
    = new System.IO.StreamReader(fileName ,System.Text.Encoding.GetEncoding(936));
       
    string line = sr.ReadToEnd();
        sr.Close();
        System.IO.StreamWriter SW = new System.IO.StreamWriter(fileName ,false,System.Text.UTF8Encoding.UTF8);   
       if(line != null)
        {
            SW.Write(line);

        }
        SW.Close();
    }
    else
        break;
    }


  • 相关阅读:
    jtopo
    转载model2
    转载model
    Vue -- 后台系统布局导航栏
    Vue -- iview表格 axiso调用接口数据
    Vue -- 视频&&下载 组件
    Vue -- echarts 折线图demo
    Vue -- axios封装
    Vue -- 验证码
    01 & 02 & 03笔记
  • 原文地址:https://www.cnblogs.com/SharkXu/p/GB2312ToUTF8.html
Copyright © 2011-2022 走看看