C#读文件中的中文时出现乱码
StreamReader reader=new StreamReader( "123.txt ",Encoding.Default);
string record=reader.ReadToEnd();
this.txtChatRecord.AppendText(record);
reader.Close();
上面的代码有问题么?怎么读出来的中文是乱码?
------解决方案--------------------StreamReader sr = new StreamReader(@ "f:\poem\唐诗三百首.txt ",System.Text.Encoding.Default);
试试这样子
------解决方案--------------------System.Text.Encoding.GetEncoding( "gb2312 ")
------解决方案-------------------- <%@Page Language= "C# " uiCulture= "auto " culture= "auto "%>
------解决方案--------------------问题在web.config文件里面:
<globalization
requestEncoding= "utf-8 "
responseEncoding= "utf-8 "
/>
字节改成:
<globalization
requestEncoding= "gb2312 "
responseEncoding= "gb2312 "
/>
就没问题了
------解决方案--------------------哟,忘了,如果是读文件的话还得加上:
<globalization requestEncoding= "gb2312 " responseEncoding= "gb2312 " culture= "zh-CN " fileEncoding= "gb2312 " />
------解决方案--------------------try..
StreamReader reader=new StreamReader( "123.txt ",Encoding.GetEncoding( "gb2312 "));
如果还是不行,看看你原来写入文件时是以什么编码形式写的?