EndOfStream in BinaryReader
-
What is the way to check for EndOfStream while using a Binary Reader ? StreamReader has the EndOfStream Property, but there seems to be no equivalent Property in BinaryReader. I am using BinaryReader because I am dealing with Byte Arrays, and sadly, StreamReader seems to insit on reading Character Arrays. And, the Stream I am reading doesn't support Seeking, so we cannot check if the Position Property is equal to the Length... I googled for it, but can't seem to find anything. Any help people ? Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com
-
What is the way to check for EndOfStream while using a Binary Reader ? StreamReader has the EndOfStream Property, but there seems to be no equivalent Property in BinaryReader. I am using BinaryReader because I am dealing with Byte Arrays, and sadly, StreamReader seems to insit on reading Character Arrays. And, the Stream I am reading doesn't support Seeking, so we cannot check if the Position Property is equal to the Length... I googled for it, but can't seem to find anything. Any help people ? Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com
Yuvi Panda wrote:
and sadly, StreamReader seems to insit on reading Character Arrays
That's what it was designed to do! From the MSDN docs on StreamReader:
StreamReader Class
Implements a TextReader that reads characters from a byte stream in a particular encoding.As for the BinaryReader[^], you're looking for it's
[PeekChar](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx)[[^](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx "New Window")]
method. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 8:57 Friday 21st April, 2006 -
Yuvi Panda wrote:
and sadly, StreamReader seems to insit on reading Character Arrays
That's what it was designed to do! From the MSDN docs on StreamReader:
StreamReader Class
Implements a TextReader that reads characters from a byte stream in a particular encoding.As for the BinaryReader[^], you're looking for it's
[PeekChar](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx)[[^](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx "New Window")]
method. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 8:57 Friday 21st April, 2006Thanks, but I am reading from a Network Stream, which Does Not support Peeking. Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com -- modified at 22:44 Friday 21st April, 2006
-
Thanks, but I am reading from a Network Stream, which Does Not support Peeking. Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com -- modified at 22:44 Friday 21st April, 2006
Hello there, I found a wayout to check for the end of stream.
using (BinaryReader br = new BinaryReader(fs)) { while(fs.Position<fs.Length) { //add your code till it finds the end of the BinaryFile line. } }
...assuming that "fs" is defined as the FileStream in the outer block. Hope this works... Mafaz