FileSystem::OpenTextFileReader Method (String^)

 

Opens a StreamReader object to read from a file.

Namespace:   Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public:
static StreamReader^ OpenTextFileReader(
	String^ file
)

Parameters

file
Type: System::String^

File to be read.

Return Value

Type: System.IO::StreamReader^

StreamReader object to read from the file

Exception Condition
ArgumentException

The file name ends with a backslash (\).

FileNotFoundException

The specified file cannot be found.

SecurityException

The user lacks necessary permissions to read from the file.

Only text files can be read with a StreamReader.

The following table lists an example of a task involving the My.Computer.FileSystem.OpenTextFileReader method.

To

See

Open a file with a StreamReader

How to: Read Text from Files with a StreamReader (Visual Basic)

This example opens the file Testfile.txt, reads a line from it, and displays the line in a MessageBox.

Dim fileReader =
  My.Computer.FileSystem.OpenTextFileReader("C:\testfile.txt")
Dim stringReader = fileReader.ReadLine()
MsgBox("The first line of the file is " & stringReader)

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

.NET Framework
Available since 2.0
Return to top
Show: