JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Writing Binary Data with the BinaryWriter Class

As discussed in the In Depth section of this chapter, once you have a FileStream object, you can use the BinaryWriter class to write binary data to a file. The BinaryWriterReader example on the CD-ROM shows how to do this, and this topic is also discussed in the In Depth section of this chapter. That example uses the BinaryWriter class's Write method to write 20 Int32 values to a file, data.dat:

Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

    'Windows Form Designer generated code

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        Dim fs As FileStream = New FileStream("data.dat", _
        Dim w As BinaryWriter = New BinaryWriter(fs)
        Dim LoopIndex As Int32

        For LoopIndex = 0 To 19
    End Sub
End Class

After writing those values to the file, you also can read them back with the BinaryReader class. See the next two topics for the details.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor