用StreamReader.ReadLine()读取文件时不能读取第一个字符例如文本文件如下
aaa.txt
___________________
aaa,bbb,ccc
ddd,eee,fff
ggg,hhh,kkk________________用ReadLine()读取出来的结果是
aa,bbb,ccc
dd,eee,fff
gg,hhh,kkk请问这是怎么回事??程序代码如下FileStream fs = new FileStream("aaa.txt",System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
StreamReader str= new StreamReader(fs,System.Text.Encoding.Default);
string aa="";
while (str.Read()!=-1)
{
aa = str.ReadLine(); Console.WriteLine(aa); } Console.ReadLine();

解决方案 »

  1.   

    你这个程序本来就是把所有文本读取出来的。while (str.Read()!=-1)  //这里是一次读取一个字符。 如果到了文本最后就返回-1。否则就继续读
    {
    aa = str.ReadLine();   //一次读一行。 看名称就知道了。 Console.WriteLine(aa); }
      

  2.   

    前面的while str.Read() 已经把第一个字符吃掉了。 所以你漏了第一个。
      

  3.   

    改成:
    while(true)
    {
      aa=str.ReadLine();
      if(aa==null) break;
      Console.WriteLine(aa);
    }
    Console.ReadLine();