p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Pro VB.NET 2002/2003 (http://p2p.wrox.com/forumdisplay.php?f=74)
-   -   Read Text file and convert to Binary file VB.net (http://p2p.wrox.com/showthread.php?t=3196)

sjlsysprg1 August 26th, 2003 09:47 AM

Read Text file and convert to Binary file VB.net
 
Hi!
Can someone show me how to convert a text file to a binary file.
Thanks
sjp

aitoshi November 11th, 2004 09:19 AM

hi
can u send me the code on how to convert from text file to binary file?


Monica December 8th, 2004 06:13 AM

Hi,

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)
        Try
            Dim bFormatter As BinaryFormatter = New BinaryFormatter
            bFormatter.Serialize(flStream, readfile)
        Finally
            flStream.Close()
            objStreamReader.Close()
        End Try
    End Sub

Cheers,
Monica

vishwanath.bmca June 29th, 2007 01:51 AM

I checked with your code,but its not working its showing same text as what i passed text file,only the first line of the file got affected.
can u check the code and send it once again please




Quote:

quote:Originally posted by Monica
 Hi,

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)
        Try
            Dim bFormatter As BinaryFormatter = New BinaryFormatter
            bFormatter.Serialize(flStream, readfile)
        Finally
            flStream.Close()
            objStreamReader.Close()
        End Try
    End Sub

Cheers,
Monica

ashu_from_india June 29th, 2007 06:53 AM

just open a BinaryReader and open the file...it will return binary data only



All times are GMT -4. The time now is 05:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.