BinaryReader.ReadBytes reads the specified number of bytes : Binary File Read « File Directory « VB.Net






BinaryReader.ReadBytes reads the specified number of bytes

 

Imports System
Imports System.IO

Public Class BinaryRW
    Shared Sub Main()
        Const upperBound As Integer = 1000
        Dim dataArray(upperBound) As Byte
        Dim randomGenerator As New Random
        randomGenerator.NextBytes(dataArray)

        Dim binWriter As New BinaryWriter(New MemoryStream())
        binWriter.Write(dataArray)
        Dim binReader As New BinaryReader(binWriter.BaseStream)
        binReader.BaseStream.Position = 0
        Dim verifyArray() As Byte = binReader.ReadBytes(dataArray.Length)
        If verifyArray.Length <> dataArray.Length Then
            Console.WriteLine("Error writing the data.")
            Return
        End If
        For i As Integer = 0 To upperBound
            If verifyArray(i) <> dataArray(i) Then
                Console.WriteLine("Error writing the data.")
                Return
            End If
        Next i
    End Sub
End Class

   
  








Related examples in the same category

1.Reading a sequential-access fileReading a sequential-access file
2.Read and Write Binary file: int, string Read and Write Binary file: int, string
3.Read from a binary fileRead from a binary file
4.Check Files Are Identical
5.BinaryReader.Read reads the specified number of characters from the stream
6.BinaryReader.ReadByte reads the next byte from the current stream
7.BinaryReader.ReadChar reads the next character from the stream