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. : Stream « File Directory « VB.Net






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

1.Stream.CanRead Property tells whether the current stream supports reading.
2.Stream.CanWrite Property tells whether the current stream supports writing.
3.Stream.CopyTo Method reads all the bytes from the current stream and writes them to the destination stream.
4.Reads a maximum of count characters from the current stream into buffer
5.Open a stream as ASCII
6.GZipStream Class
7.Compress streams
8.Decompress streams.
9.Stream.CanWrite Property tells whether the current stream supports writing.