Use BinaryWriter to store information into a binary file : Binary File Write « File Directory « VB.Net






Use BinaryWriter to store information into a binary file

 
Imports System
Imports System.IO

Public Class MainClass

  Shared Sub Main()

    Dim aFileStream As FileStream
    Try
      aFileStream = New FileStream("test.txt", FileMode.OpenOrCreate,FileAccess.Write)
      Dim myBinaryWriter As New BinaryWriter(aFileStream)
      myBinaryWriter.Write("Hello world")
      myBinaryWriter.Write(1)
    Catch e As Exception
      Console.WriteLine(e.StackTrace)
    Finally
      If Not (aFileStream Is Nothing) Then aFileStream.Close()
    End Try
  End Sub
  
End Class


           
         
  








Related examples in the same category

1.Creating a random file
2.Save Structure to a Binary File
3.Gets the underlying stream of the BinaryWriter.
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