Mega Code Archive

 
Categories / VB.Net / File Directory
 

Writes a region of a byte array to the current stream

Imports System Imports System.IO Public Class BinaryRW     Shared Sub Main()         Const upperBound As Integer = 100         Dim dataArray(upperBound) As Byte         Dim randomGenerator As New Random         randomGenerator.NextBytes(dataArray)         Dim binWriter As New BinaryWriter(New MemoryStream())         binWriter.Write(dataArray, 0, dataArray.Length)         Dim binReader As New BinaryReader(binWriter.BaseStream)         binReader.BaseStream.Position = 0         Dim verifyArray(upperBound) As Byte         If binReader.Read(verifyArray, 0, dataArray.Length) <> dataArray.Length Then             Console.WriteLine("Error writing the data.")             Return         End If     End Sub End Class