BinaryReader.ReadByte reads the next byte from the current stream
Imports System
Imports System.IO
Public Class BinaryRW
Shared Sub Main()
Dim i As Integer = 0
Dim writeArray(1000) As Byte
Dim randomGenerator As New Random()
randomGenerator.NextBytes(writeArray)
Dim binWriter As New BinaryWriter(New MemoryStream())
Dim binReader As New BinaryReader(binWriter.BaseStream)
Try
For i = 0 To writeArray.Length - 1
binWriter.Write(writeArray(i))
Next i
binReader.BaseStream.Position = 0
For i = 0 To writeArray.Length - 1
If binReader.ReadByte() <> writeArray(i) Then
Console.WriteLine("Error writing the data.")
Return
End If
Next i
Catch ex As EndOfStreamException
Console.WriteLine("Error writing the data: {0}",ex.GetType().Name)
End Try
End Sub
End Class
Related examples in the same category