OpenTextFileReader Method (String, Encoding)
Collapse the table of content
Expand the table of content

FileSystemProxy.OpenTextFileReader Method (String, Encoding)

 

Opens a StreamReader object to read from a file.

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

public StreamReader OpenTextFileReader(
	string file,
	Encoding encoding
)

Parameters

file
Type: System.String

File to be read.

encoding
Type: System.Text.Encoding

The encoding to use for the file contents. Default is ASCII.

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 examples of tasks 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:
© 2016 Microsoft