为啥我用streamreader的时候读出来的英文是好的,但是中文就不是好的了,成乱码了

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为啥我用streamreader的时候读出来的英文是好的,但是中文就不是好的了,成乱码了相关的知识,希望对你有一定的参考价值。

高手指教下

解决方法是System.Text.Encoding.Default 告诉
StreamReader 目前操作系统的编码即可。

StreamReader reader = new StreamReader(FileName, System.Text.Encoding.Default)
参考技术A StreamReader sr = new StreamReader("d:\\zwsj.txt",System.Text.Encoding.Default);
StreamWriter sw = new StreamWriter("d:\\haha.txt", true);
string strline;
try

strline = sr.ReadLine();
while (strline != null)

strline = sr.ReadLine();
sw.WriteLine(strline);

sr.Close();
sw.Close();

catch (IOException f)

Console.WriteLine(f.ToString());

以上是关于为啥我用streamreader的时候读出来的英文是好的,但是中文就不是好的了,成乱码了的主要内容,如果未能解决你的问题,请参考以下文章