Edit

Share via


FileSystemProxy.OpenTextFileReader Method

Definition

Opens a StreamReader object to read from a file.

Overloads

OpenTextFileReader(String)

Opens a StreamReader object to read from a file.

OpenTextFileReader(String, Encoding)

Opens a StreamReader object to read from a file.

OpenTextFileReader(String)

Opens a StreamReader object to read from a file.

public:
 System::IO::StreamReader ^ OpenTextFileReader(System::String ^ file);
public System.IO.StreamReader OpenTextFileReader (string file);
member this.OpenTextFileReader : string -> System.IO.StreamReader
Public Function OpenTextFileReader (file As String) As StreamReader

Parameters

file
String

File to be read.

Returns

StreamReader object to read from the file.

Exceptions

The file name ends with a backslash (\).

The specified file cannot be found.

The user lacks necessary permissions to read from the file.

Examples

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)

Remarks

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

See also

Applies to

OpenTextFileReader(String, Encoding)

Opens a StreamReader object to read from a file.

public:
 System::IO::StreamReader ^ OpenTextFileReader(System::String ^ file, System::Text::Encoding ^ encoding);
public System.IO.StreamReader OpenTextFileReader (string file, System.Text.Encoding encoding);
member this.OpenTextFileReader : string * System.Text.Encoding -> System.IO.StreamReader
Public Function OpenTextFileReader (file As String, encoding As Encoding) As StreamReader

Parameters

file
String

File to be read.

encoding
Encoding

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

Returns

StreamReader object to read from the file.

Exceptions

The file name ends with a backslash (\).

The specified file cannot be found.

The user lacks necessary permissions to read from the file.

Examples

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)

Remarks

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

See also

Applies to