Hello,

I am new to using the FileStream class. I have the following code, but do not fully understand it:

Code:
Using myFile As New FileStream(myPath, FileMode.Open, FileAccess.Read)
    Try

        Dim myChunk = 999
        Dim myFileLen As Integer = CInt(myFile.Length)
        Dim myBuff(myFileLen) as Byte
        Dim myBlock(myChunk) as Byte
        Dim myCount As Integer = -1
        Dim myPos As Integer = 256

        While myCount <> 0
            myCount = myFile.Read(myBlock, 0, myChunk-1)
            Array.Copy(myBlock, 0, myBuff, myPos, myCount)
            myPos = myPos + myCount
        End While

        For Each myElement As Integer In myBuff
            Console.WriteLine(myElement)
        Next

    End Try
End Using
I have a binary file that contains a lot of 8 bit Bytes (0-255) and no words. I was just looking for a simple way to read the file from point x and read n number of Bytes.

For example starting at Byte 256, read 999 Bytes from the file.

Do you have to read them into an array when using FileStream?

It seems like I have a lot of variables for what I am trying to do. Can I simplify it?

My file is 35MB in size. Not huge, but I'd rather deal with chunks of data and be able to start the chunk at any position in the file. I'd also rather load each Byte one at time, convert to whatever and display it or do whatever to it. Then if I need to, load another chunk.

Thank you.