how to use a buffer to store all the content of bnary file

  • Thread starter Thread starter JC
  • Start date Start date
J

JC

HI

I want to use a byte array to store all the content of a file. Is there
anyway allow me to do so?

Thx

JC
 
I want to use a byte array to store all the content of a file. Is there
anyway allow me to do so?

read the contents of a file into a byte array like this:

Dim Filespec as string = "..." ' your file name goes here
Dim fs As IO.FileStream = Nothing
Dim Buffer() As Byte = Nothing
Try
fs = New IO.FileStream(Filespec, IO.FileMode.Open)
ReDim Buffer(CInt(fs.Length))
fs.Read(Buffer, 0, Buffer.Length)
Catch ex As Exception
' whatever you want goes here
Finally
If Not fs Is Nothing Then fs.Close()
End Try
' Buffer() contains the file or your Catch code has done something helpful
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top