I'm trying to read the binary data from a binary file with the code below but the it's return the value in the byte array. How can i read the binary data from the binary file and then convert the data into string?

This is how i create the binary file.

Dim fs As New FileStream(Application.StartupPath & "\Agency.dat", FileMode.OpenOrCreate)
    Dim bf As New BinaryFormatter()
    Call bf.Serialize(fs, GAgency)
    fs.Close()

Code to read the binary file.

Public Shared Function ReadBinaryFile(ByVal path As String)
    ' Open the binary file.
    Dim streamBinary As New FileStream(path, FileMode.Open)

    ' Create a binary stream reader object.
    Dim readerInput As BinaryReader = New BinaryReader(streamBinary)

    ' Determine the number of bytes to read.
    Dim lengthFile As Integer = FileSize(path)

    ' Read the data in a byte array buffer.
    Dim inputData As Byte() = readerInput.ReadBytes(lengthFile)

    ' Close the file.
    streamBinary.Close()
    readerInput.Close()

    Return inputData
End Function 'ReadBinaryData’
share|improve this question

66% accept rate
feedback

1 Answer

up vote 0 down vote accepted

try as

Dim objGAgency As GAgency
Dim fs As Stream = New FileStream( Application.StartupPath & "\Agency.dat", FileMode.Open)
Dim bf As BinaryFormatter = New BinaryFormatter()

objGAgency = CType(bf.Deserialize(fs), GAgency)
fs.Close()
share|improve this answer
tried. Return nothing. – Danferd Lan Jun 22 at 4:19
have you try to Deserialize it? – Damith Jun 22 at 4:40
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.