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: ,,,,,,,,,,,,,,,,,,,
,,,,,,,,

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: