Jump to content

Visual Basic Read File Content

- - - - -

  • Please log in to reply
No replies to this topic

#1
QuackWare

QuackWare

    Learning Programmer

  • Members
  • PipPipPip
  • 95 posts
Visual Basic Read File Content



/** This code snippet was taken from freecodesnippets.com*/ 


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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users