FileSystemProxy.OpenTextFileReader Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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)
- Source:
- FileSystemProxy.vb
- Source:
- FileSystemProxy.vb
- Source:
- FileSystemProxy.vb
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
- Encoding
- StreamReader
- Objects (Visual Basic)
- How to: Read Text from Files with a StreamReader (Visual Basic)
- Reading from Files in Visual Basic
Applies to
OpenTextFileReader(String, Encoding)
- Source:
- FileSystemProxy.vb
- Source:
- FileSystemProxy.vb
- Source:
- FileSystemProxy.vb
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
- Encoding
- StreamReader
- Objects (Visual Basic)
- How to: Read Text from Files with a StreamReader (Visual Basic)
- Reading from Files in Visual Basic