Filestream Byte Sections

davesil2

Member
Joined
Oct 27, 2003
Messages
16
Location
Chicagoland Area
Im trying to pass sections of the byte array at a time with error checking. Right now I have code that I thought would work but appearantly does not.

Basically Im trying to read a file into the stream reader then pick a section of byte to grab from it to pass to something else. Im basically using something close the the following pseudo code.

dim fs as filestream = new filestream("C:\autoexec.bat", FileMode.open)
dim ByteFileSection() as byte = new byte(50) {} (Im not sure what the curly brackets do)
fs.read(bytefilesection, startByte, length)

I basically do this in a loop and the startbyte increases by 50 every time arround. Perhaps someone has an example or something that I might be able to use.

-David Silberhorn
 
something like this?
Code:
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim fs As New FileStream("c:\dummy.txt", FileMode.Open)
		Dim tr As New BinaryReader(fs)
		While tr.BaseStream.Position < tr.BaseStream.Length
			Dim bytes(50) As Byte
			bytes = tr.ReadBytes(bytes.Length)
			ProcessBytes(bytes)
		End While
	End Sub
 
	Private Sub ProcessBytes(ByVal bytes() As Byte)
		Dim ascii As New ASCIIEncoding
		Dim decoded As String = ascii.GetString(bytes)
		TextBox1.AppendText(decoded)
	End Sub
 
Back
Top