Reputation: 2913
I am trying to read a large text file (4000+ lines) and output each line to console. I am using the following code
using (var reader = new StreamReader("list1.txt"))
{
while (!reader.EndOfStream)
Console.WriteLine(reader.ReadLine().Trim());
}
Console.Read();
This reads the lines, but the problem is the reading starts from line 4113 when it should be starting from line one correct? So that means I am only get 100 or so of the lines from the text file. Why would this be occuring?
Thanks.
Upvotes: 3
Views: 352
Reputation: 882646
You may well find that the output window only shows you the last N
lines, where N
is around 100. In other words, the scrollback buffer is smaller than you think.
You can check this by changing your code to something like:
int numlines = 0;
using (var reader = new StreamReader("list1.txt")) {
while (!reader.EndOfStream) {
Console.WriteLine(reader.ReadLine().Trim());
numlines++;
}
}
Console.WriteLine("Wrote " + numlines + " lines.");
Console.Read();
which will output the number of lines processed at the end.
You can change the console height with a command like:
Console.BufferHeight = 30000;
Upvotes: 2
Reputation: 2913
As suggested by a user I needed to increase Bufferheight to acomodate the lines of text.
Upvotes: 2