C# StreamReader.Readline() 出现一次读取多行怎么办

试了好几个文件,内容是英文的,大小不超过5k,但是每次都在大概31,32行时一下冒出两行来,然后就彻底乱了

代码如下
FileStream abcFile = new FileStream("abc.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(abcFile);
String[] str1 = new String[96];
String[] str2 = new String[96];
str1[0] = sr.ReadLine();
for (int i = 0; str1[0] != null; i++)
{
str2[i] = sr.ReadLine();
str1[i+1] = sr.ReadLine();
}
写入的时候要清缓冲,读取有缓冲吗,我找了也没找到

StreamReader sr = new StreamReader("data.txt", Encoding.Default);
//记得编码,不然读取汉字时会出错的
string text = sr.ReadToEnd();
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-05-10
string[] str= File.ReadAllLines("abc.txt");
//如果一定要用StreamReader可以这样写
using (StreamReader sr = new StreamReader("abc.txt"))
{
 while (sr.Peek() >= 0) 
 {
 Console.WriteLine(sr.ReadLine()); 
 }
}

本回答被提问者和网友采纳
相似回答