0

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’

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

have you try to Deserialize it?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.