首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请教,这个读取文件,为什么是乱码呢

2012-04-06 
请问,这个读取文件,为什么是乱码呢?static void Main(string[] args){string s1 @D:\pp.txtusing (St

请问,这个读取文件,为什么是乱码呢?
static void Main(string[] args)
  {
  string s1 = @"D:\pp.txt";
  using (StreamReader sr = new StreamReader(s1))
  {  
  while (!sr.EndOfStream) //利用EndOfStream属性判断流的当前位置,是否在流的末尾
  {
  Console.WriteLine(sr.ReadLine());
  }  
  }
  Console.ReadKey();
  }


为什么输出结果是乱码呢?

[解决办法]
bian ma wen ti
[解决办法]
改成这样:

C# code
using (StreamReader sr = new StreamReader(s1, Encoding.GetEncoding("gb2312")))
[解决办法]
探讨

引用:

引用:
static void Main(string[] args)
{
string s1 = @"D:\pp.txt";
using (StreamReader sr = new StreamReader(s1))
{
while (!sr.E……


StreamReader sr =……

热点排行