BinaryReader: ReadByte

ReadByte

Reads the next byte in the stream, and advances the position one byte.



 Public Function ReadByte ( ) As Byte

Return Values

Byte -  The next byte in the stream.

Remarks

BinaryReader does not restore the file position after an unsuccessful read.

Exceptions

Exception Condition
EndOfStreamExceptionThe end of the stream is reached.
ObjectDisposedExceptionThe stream is closed.
IOExceptionAn I/O error occurs.

Examples

The following example writes a 32-bit integer value then reads it back one byte at a time using ReadByte.

Public Sub Main()
    Dim Source As New MemoryStream
    Dim Reader As BinaryReader
    Dim Writer As BinaryWriter
    
    Set Writer = NewBinaryWriter(Source, New UnicodeEncoding)
    Writer.WriteValue &H80706050    
    
    Source.Position = 0
    
    Set Reader = NewBinaryReader(Source)
    
    PrintByte Reader.ReadByte
    PrintByte Reader.ReadByte
    PrintByte Reader.ReadByte
    PrintByte Reader.ReadByte
End Sub

Private Sub PrintByte(ByVal Value As Byte)
    Debug.Print CorString.Format("&h{0:X2}", Value)
End Sub


' This example code produces the following output.
'
'   &h50
'   &h60
'   &h70
'   &h80

See Also

Project CorLib Overview

Class BinaryReader Overview

Read

ReadBytes

CorString

Constructors