Reads a maximum of count characters from the current stream into buffer : Stream « File Directory « VB.Net






Reads a maximum of count characters from the current stream into buffer

 

Imports System
Imports System.IO
Imports System.Text

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"
        Try
            If File.Exists(path) Then
                File.Delete(path)
            End If
            Dim sw As StreamWriter = New StreamWriter(path)
            sw.WriteLine("This is a test")
            sw.WriteLine("This is a test")
            sw.WriteLine("This is a test")
            sw.WriteLine("This is a test")
            sw.Close()
            Dim sr As StreamReader = New StreamReader(path)
            Do While sr.Peek() >= 0
                Dim c(5) As Char
                sr.Read(c, 0, c.Length)
                Console.WriteLine(c)
            Loop
            sr.Close()
        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    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.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.
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.