How to: Read Text from a File
The following code examples show how to read text from a text file. The second example notifies you when the end of the file is detected. This functionality can also be achieved by using theor methods.
This code creates a StreamReader that points to MyFile.txt through a call to File.OpenText. StreamReader.ReadLine returns each line as a string. When there are no more characters to read, a message is displayed to that effect, and the stream is closed.
Visual Basic users may choose to use the methods and properties provided by the My.Computer.FileSystem object for file I/O. For more information, see.