从文本文件中读取汉字时产生乱码,英文和数字则没有任何问题,求解决办法!

解决方案 »

  1.   

    设置response.encode和request.encode一致。,
      

  2.   

    编码的问题
    使用
    Encoding.Deafault
    或者
    Encoding.GetEncoding("GB2312");
      

  3.   

    System.Text.Encoding.GetEncoding("GB2312")
      

  4.   

    更新web.config文件,把所有编码方式改成gb2312
      

  5.   

    简单的说就是在 web.config 里面改 ,替换所有 utf-8 ,改成 gb2312
      

  6.   

    StreamReader srdNews = null;
    try
    {
             //取得文件的实际路径
    string file_path = Server.MapPath("News.txt");
    //打开文件进行读取
    srdNews = File.OpenText(file_path);
    while(srdNews.Peek() != -1)
    {
    lblNews.Text = srdNews.ReadLine();
    }
    }
    catch(IOException err)
    {
    Response.Write(err.Message);
    }
    finally
    {
    srdNews.Close();
    }
    这是我从文本文件News.txt读取数据的代码,可是lblNews.Text显示出来的汉字全是乱码(英文和数字没有任何问题),编码方式也设置为gb2312了,各位高手帮忙啊!
      

  7.   

    FileStream fs=File.Open(file_path,FileMode.Open,FileAccess.Read);StreamReader fsread = new StreamReader(fs,System.Text.Encoding.GetEncoding("gb2312"));while(fsread.Peek() != -1)
    {
    lblNews.Text = fsread.ReadLine();
    }
      

  8.   

    用Encoding.Default和Encoding.GetEncoding("gb2312")有什么区别吗?
      

  9.   

    这个问题我自己也碰到过,抄别人的程序,读取出来总是出现乱码,后来自己写了一个,奇怪,没有问题了.
    /// <summary>
    /// 读取文本
    /// </summary>
    /// <param name="filePath">要读取的文件路径及名称</param>
    /// <returns>返回该文本的全部内容</returns>
    public string myReadText(string filePath)
    {
    StreamReader myr = File.OpenText(filePath);
    string mystr = myr.ReadToEnd();
    myr.Close();
    return(mystr);
    }
      

  10.   

    StreamReader fsread = new StreamReader("c:\1.txt",System.Text.Encoding.Default);