View Single Post
  #3 (permalink)  
Old December 8th, 2004, 06:13 AM
Monica Monica is offline
Registered User
Join Date: Jan 2004
Location: , , India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts


Here's a sample code to convert a text file to a binary file

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Class1

    Public Sub BinarySerialize()
        'Create a streamreader class
        Dim objStreamReader As StreamReader
        'open the file
        objStreamReader = File.OpenText("c:\\Mystore1.txt")
        'Read the file storing it in the readfile string
        Dim readfile As String = objStreamReader.ReadToEnd()
        Dim flStream As FileStream = New FileStream("c:\\myStore.txt", FileMode.OpenOrCreate, FileAccess.Write)
            Dim bFormatter As BinaryFormatter = New BinaryFormatter
            bFormatter.Serialize(flStream, readfile)
        End Try
    End Sub