lesson 10.6 - Binary file

0 views
Skip to first unread message

Justin

unread,
Sep 8, 2007, 6:12:11 AM9/8/07
to Exam Bells !!! - Group for Sem exam preparation
output
=====

create a new binary file

++++++++++++
write to binary file
+++++++++++++


++++++++++++
Read from the file ____________________-
++++++++++++


output of the file is


____________________________________


*************************************************************


Imports system.io

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim files As FileStream = New FileStream("D:\delete-this-folder
\binaryfile.bin", FileMode.OpenOrCreate)

Dim bw As BinaryWriter = New BinaryWriter(files)


Dim j As Integer

For j = 1 To 5
bw.Write(CStr(j))


Next

files.Close() '<<dont forget this !!!!!
'if you dont give the close, you wont be able to see any
output
' if you open the file
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click

Dim fileName As String
fileName = TextBox1.Text
Dim binWritefile As FileStream = New FileStream(fileName,
FileMode.OpenOrCreate)

Dim br As BinaryReader = New BinaryReader(binWritefile)
br.BaseStream.Seek(0, SeekOrigin.Begin)
TextBox2.Text = br.ReadChars(50)

'find a way to specify the end ^^^of file rather than
specifying a number

End Sub
End Class

Reply all
Reply to author
Forward
0 new messages