OpenTextFileReader Method


OpenTextFileReader Method

Location

My.Computer.FileSystem.OpenTextFileReader

Syntax

     Dim result As System.IO.StreamReader = _        My.Computer.FileSystem.OpenTextFileReader(path[, encoding]) 


path (required; String)

The path of the file to read.


encoding (optional; Encoding)

The character encoding method to use, as a System.Text.Encoding object. If this parameter is missing, ASCII is used as the default encoding method.

Description

The OpenTextFileReader opens a file for text reading and returns a stream of type System.IO.StreamReader.

Public Members

The returned StreamReader object includes the following notable public members.

Member

Description

Close

Method. Closes the file.

ReadLine

Method. Reads one line from the file and returns it as a string.


Usage at a Glance

  • An exception is thrown if the path parameter is missing or invalid, or if the file it refers to does not exist.

  • An exception is thrown if the user lacks sufficient file access permissions.

Example

     Dim oneLine As String     Dim inputFile As System.IO.StreamReader = _        My.Computer.FileSystem.OpenTextFileReader("c:\temp\data.txt")     Do While inputFile.EndOfStream = False        oneLine = inputFile.ReadLine(  )        ' ----- Process data here...     Loop     inputFile.Close(  ) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.FileSystem.OpenTextFileReader Method

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.OpenTextFileReader Method

  • System.IO.StreamReader Class

  • System.IO.TextReader Class

See Also

FileSystem Object, OpenTextFieldParser Method, OpenTextFileWriter Method, ReadAllBytes Method, ReadAllText Method, WriteAllBytes Method, WriteAllText Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net