读书人

[10分] 无法读取文本文件内的中文(Wi

发布时间: 2012-03-14 12:01:12 作者: rapoo

[10分] 无法读取文本文件内的中文(WinForm)
在桌面新建一个文本文件,里面输入诺干中文字符。然后在 WinForm 的 TextBox 内读取:

StreamReader sr = new StreamReader( "C:\..\桌面\new.txt ");

string strEachLine = " ";
ArrayList alText = new ArrayList();

while (strEachLine != null)
{
strEachLine = sr.ReadLine();
if (strEachLine != null)
alText.Add(strEachLine);
}

foreach (string s in alText)
{
txbTextDetail.Text += s;
}

但是显示出来的是乱码,请问如何解决?

[解决办法]
StreamReader sr = new StreamReader( "C:\..\桌面\new.txt ",Encoding.GetEncoding( "GB2312 "));
多个括号
[解决办法]
StreamReader sr = new StreamReader(@ "C:\..\桌面\new.txt ",Encoding.Default);

读书人网 >C#

热点推荐