c#如何来读入中文内容的txt文件

school0911 2004-03-23 08:01:59
我想把中文内容的txt文件里的内容读到程序里的字符串中,读到的内容都是乱码,请问如何才能读入正确的中文内容?
...全文
83 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
school0911 2004-03-24
  • 打赏
  • 举报
回复
哦,谢谢大家了!
yuewenbin 2004-03-23
  • 打赏
  • 举报
回复
System.Text.Encoding.Default
HNU 2004-03-23
  • 打赏
  • 举报
回复


System.Text.Encoding.Default是关键
Aglie 2004-03-23
  • 打赏
  • 举报
回复
using System.IO
StreamReader str=new StreamReader(@"c:\t.txt",System.Text.Encoding.Default);
str.WriteLine("xxxx");
007Delphi 2004-03-23
  • 打赏
  • 举报
回复
StreamReader sr=new StreamReader("c:\\x.txt",System.Text.Encoding.Default);
yanlong 2004-03-23
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2872/2872757.xml?temp=.5741846
dxhdxh2k 2004-03-23
  • 打赏
  • 举报
回复
System.IO.StreamReader sr=new System.IO.StreamReader(@"d:\\test5.txt",System.Text.Encoding.GetEncoding("GB2312"));
starheart 2004-03-23
  • 打赏
  • 举报
回复
up
bitsbird 2004-03-23
  • 打赏
  • 举报
回复
StreamReader sw = File.OpenText(@"d:\a.txt");
string str;
while((str =sw.ReadLine()) != null)
{
textBox2.Text = str;
}
xhan2000 2004-03-23
  • 打赏
  • 举报
回复
StreamReader sr=new StreamReader("c:\\x.txt",System.Text.Encoding.Default);
bitsbird 2004-03-23
  • 打赏
  • 举报
回复
StreamWriter sw = File.CreateText(@"d:\a.txt");
sw.Write("hello");
sw.WriteLine("hello");
sw.Close()

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧