Writes a Unicode character : Binary File Write « File Directory « VB.Net






Writes a Unicode character

 

Imports System
Imports System.IO

Public Class BinaryRW
    Shared Sub Main()
        Dim i As Integer = 0
        Dim invalidPathChars() As Char = Path.InvalidPathChars
        Dim memStream As new MemoryStream()
        Dim binWriter As New BinaryWriter(memStream)

        binWriter.Write("test: ")
        For i = 0 To invalidPathChars.Length - 1
            binWriter.Write(invalidPathChars(i))
        Next i

        Dim binReader As New BinaryReader(memStream)
        memStream.Position = 0

        Console.Write(binReader.ReadString())
        Dim memoryData( CInt(memStream.Length - memStream.Position) - 1) As Char
        For i = 0 To memoryData.Length - 1
            memoryData(i) = binReader.ReadChar()
        Next i
        Console.WriteLine(memoryData)

  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.BinaryWriter.Write(Byte[]) Writes a byte array to the underlying stream.
8.Writes a region of a byte array to the current stream.
9.Writes a character array
10.Writes a section of a character array
11.Writes a length-prefixed string