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!
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.
End Function ‘ReadBinaryData’
Public Shared Function FileSize(ByVal path As String) As Integer
Dim info As New FileInfo(path)
End Function ‘FileSize’
Technorati Tags: vb.net,.NET Framework,csharp,IO,Read,Binary,File,System,Public,Class,Function,path,Byte,Open,FileStream,FileMode,Create,reader,BinaryReader,