Gets the underlying stream of the BinaryWriter. : Binary File Write « File Directory « VB.Net






Gets the underlying stream of the BinaryWriter.

 

Imports System
Imports System.IO

Public Class BinaryRW
    Shared Sub Main()
        Dim i As Integer
        Const upperBound As Integer = 1000
        Dim dataArray(upperBound) As Double
        For i = 0 To upperBound
            dataArray(i) = 100.1 * i
        Next i

        Dim binWriter As New BinaryWriter(New MemoryStream())
        Try
            For i = 0 To upperBound
                binWriter.Write(dataArray(i))
            Next i
            Dim binReader As New BinaryReader(binWriter.BaseStream)
            binReader.BaseStream.Position = 0
            Try
                For i = 0 To upperBound
                    If binReader.ReadDouble() <> dataArray(i) Then
                        Console.WriteLine("Error writing data.")
                        Exit For
                    End If
                Next i
            Catch ex As EndOfStreamException
                Console.WriteLine("Error writing data: {0}.",ex.GetType().Name)
            End Try
        Finally
            binWriter.Close()
        End Try
    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.BinaryWriter.Seek Method Sets the position within the current stream.
5.BinaryWriter.Write Method Writes an unsigned byte to the current stream and advances the stream position by one byte.
6.BinaryWriter.Write(Byte[]) Writes a byte array to the underlying stream.
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