VB.net Program to Demonstrate the Binaryreader and Binarywriter Class

You are currently viewing VB.net Program to Demonstrate the Binaryreader and Binarywriter Class

VB.Net program to demonstrate the BinaryReader and BinaryWriter class

'Vb.Net program to demonstrate the 
'BinaryReader and BinaryWriter class.

Imports System.IO

Module Module1
    Class Sample
        Private fileName As String = "sample.txt"
        Public Sub WriteData()
            Dim f As FileStream = File.Open(fileName, FileMode.Create)

            Dim bwriter As New BinaryWriter(f)

            bwriter.Write(108)
            bwriter.Write("All the best")

            f.Close()
        End Sub

        Public Sub PrintData()
            Dim luckyNum As Integer = 0
            Dim msg As String = ""

            Dim f As FileStream = File.Open(fileName, FileMode.Open)

            Dim breader As New BinaryReader(f)

            luckyNum = breader.ReadInt32()
            msg = breader.ReadString()

            Console.WriteLine("Lucky Number : " & luckyNum)
            Console.WriteLine("String       : " & msg)

            f.Close()
        End Sub
    End Class

    Sub Main()
        Dim S As New Sample()

        S.WriteData()
        S.PrintData()
    End Sub
End Module
Lucky Number : 108
String       : All the best
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply