我写了一个代码来读.txt文件,文件中有汉字
                StreamReader sr = File.OpenText(FileName);
                string s = "";
                s = sr.ReadLine();
可是这样读出来的汉字是乱码,怎样才能读到汉字呢?

解决方案 »

  1.   

    StreamReader sr = new StreamReader( FileName, Encoding.GetEncoding( "gb2312" ));
      

  2.   

    http://www.tectnet.com/Print.asp?ThreadID=1892
      

  3.   

    编码方式的问题,File.OpenText方法只能打开UTF-8 编码文本文件,如果该文件不是以UTF-8编码方式保存的,那么就要先把它以字节流的方式读取,然后用System.Text.Encodeing下的方法进行编码转换为字符串
      

  4.   

    StreamReader sr = new StreamReader(open_File.FileName,System.Text.Encoding.Default);
    用这个就可以了