How to VB.NET BinaryWriter

The BinaryWriter Object works at lower level of Streams. BinaryWriter is used for write premitive types as binary values in a specific encoding stream. BinaryWriter Object works with Stream Objects that provide access to the underlying bytes. For creating a BinaryWriter Object , you have to first create a FileStream Object and then pass BinaryWriter to the constructor method.

The main advantages of Binary information is that it is not easily human readable and stores files as Binary format is the best practice of space utilization.

Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
        Dim writeStream As FileStream
writeStream = New FileStream("c:\testBinary.dat", FileMode.Create)
            Dim writeBinay As New BinaryWriter(writeStream)
            writeBinay.Write("This is a test for BinaryWriter !")
        Catch ex As Exception
        End Try
    End Sub
End Class

BinaryReader you can use in the same way to read as binary. (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About