This documentation is archived and is not being maintained.

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 the ReadAllLines or ReadAllText methods.

Example

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

Robust Programming

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.

NoteNote

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 My.Computer.FileSystem Object.

See Also

Show: