Read A Binary File with vb.net

Good Morning! I did not sleep well last night. That happens to me often but it was particularly bad last night. And on top of that I have a long list of meetings I have to do today so I can’t be sleepy, disinterested or crabby or even appear to be those. So hoping this day is over quickly is my prayer!

Today’s topic is how to read a binary file with vb.net. I was asked so I decided to make it a blog post. Make it a great day!


Join me on Facebook

Imports System.IO

Public Class IO_Library

  Public Shared Function ReadBinaryData(ByVal path As String) As Byte()

    ‘ 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’

  Public Shared Function FileSize(ByVal path As String) As Integer

    Dim info As New FileInfo(path)

    Return info.Length

  End Function ‘FileSize’

End Class ‘IO_Library’


Join me on Facebook

Technorati Tags: ,,,,,,,,,,,,,,,,,,,
,,,,,,,,

  1. Leave a comment

Leave a comment