C# StreamReader ReadToEnd
Description
StreamReader ReadToEnd
Reads all characters from the
current position to the end of the stream.
Syntax
StreamReader.ReadToEnd
has the following syntax.
public override string ReadToEnd()
Returns
StreamReader.ReadToEnd
method returns The rest of the stream as a string, from the current position to the end. If
the current position is at the end of the stream, returns an empty string ("").
Example
The following code example reads all the way to the end of a file in one operation.
/*from w w w . jav a 2 s . com*/
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))
{
Console.WriteLine(sr.ReadToEnd());
}
}
}