BinaryWriter.Write(Byte[]) Writes a byte array to the underlying stream. : Binary File Write « File Directory « VB.Net






BinaryWriter.Write(Byte[]) Writes a byte array to the underlying stream.

 

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
    End Sub
End Class

   
  








Related examples in the same category

1.Creating a random file
2.Use BinaryWriter to store information into a binary file
3.Save Structure to a Binary File
4.Gets the underlying stream of the BinaryWriter.
5.BinaryWriter.Seek Method Sets the position within the current stream.
6.BinaryWriter.Write Method Writes an unsigned byte to the current stream and advances the stream position by one byte.
7.Writes a region of a byte array to the current stream.
8.Writes a Unicode character
9.Writes a character array
10.Writes a section of a character array
11.Writes a length-prefixed string