Read all file content : Stream Reader « File Directory « VB.Net






Read all file content

Read all file content
 
Imports System.IO

Module Module1

    Sub Main()
        Dim TextFile As StreamReader

        Try
            TextFile = New StreamReader("test.txt")
        Catch E As Exception
            Console.WriteLine("Error opening the file test.txt")
            Console.WriteLine("Error {0}", E.Message)
        End Try

        Dim Content As String

        Try
            Content = TextFile.ReadToEnd()
            Console.WriteLine(Content)
        Catch E As Exception
            Console.WriteLine("Error reading file")
            Console.WriteLine("Error {0}: ", E.Message)
        End Try

        TextFile.Close()

    End Sub

End Module


           
         
  








Related examples in the same category

1.Stream Reader DemoStream Reader Demo
2.Stream Reader: read intStream Reader: read int
3.StreamReader Class implements a TextReader that reads characters from a byte stream in a particular encoding.
4.Create StreamReader class for the specified stream.
5.Create StreamReader class for the specified file name.
6.StreamReader.Read reads the next character from the input stream
7.Display Integer read from a StreamReader in hex format
8.StreamReader Class Implements a TextReader that reads characters from a byte stream in a particular encoding.