March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System;
using System.IO;
using System.Text;
namespace Samples
{
public class EndOfStreamExceptionSample
{
public static void Main()
{
string s = "filestream.txt";
FileStream fs = new FileStream(s, FileMode.Open);
BinaryReader br =
new BinaryReader(fs, Encoding.ASCII );
try
{
while(true)
{
char c = br.ReadChar();
}
}
catch(EndOfStreamException e )
{
Console.WriteLine("Exception: {0}", e);
}
}
}
}
Exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream. at System.IO.__Error.EndOfFile() at System.IO.BinaryReader.ReadChar() at Samples.EndOfStreamExceptionSample.Main() in C:\Books\BCL\Samples\System.IO \EndOfStreamException\EndOfStreamException.cs:line 19
Read now
Unlock full access