Stream.Read Method reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Imports System
Imports System.IO
Public Class Block
Public Shared Sub Main()
Dim s As Stream = New MemoryStream()
For i As Integer = 0 To 99
s.WriteByte(CType(i, Byte))
Next i
s.Position = 0
Dim bytes(s.Length) As Byte
Dim numBytesToRead As Integer = s.Length
Dim numBytesRead As Integer = 0
Dim n As Integer
While numBytesToRead > 0
n = s.Read(bytes, numBytesRead, 10)
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
s.Close()
Console.WriteLine("number of bytes read: {0:d}", numBytesRead)
End Sub
End Class
Related examples in the same category