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 . . .
Table of Contents