C# StreamReader ReadLine
Description
StreamReader ReadLine
Reads a line of characters from
the current stream and returns the data as a string.
Syntax
StreamReader.ReadLine
has the following syntax.
public override string ReadLine()
Returns
StreamReader.ReadLine
method returns The next line from the input stream, or null if the end of the input stream is
reached.
Example
The following code example reads lines from a file until the end of the file is reached.
/* ww w .ja va 2 s .c o m*/
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine("This");
sw.WriteLine("is from java2s.com");
}
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
Console.WriteLine(sr.ReadLine());
}
}
}
}