Try this
BinaryReader br=new BinaryReader(File.OpenRead(filename));
try
{
while(true)
{
br.ReadInt32();
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Raises an exception at the end of file ??? thats nothing unusual. then try this
BinaryReader br=new BinaryReader(File.OpenRead(filename));
try
{
while(true)
{
br.ReadBytes(4);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
It doesnt raises exception right ?? why ?? Both readbytes(4) and readint32() reads 4 bytes and increment pointer by 4 bytes. But one raises exception at end of file while other doesnt.
if anyone can explain this, please leave a comment.