OpenTextFileReader

Opens a StreamReader object to read from a file.


Syntax

FileSystem.OpenTextFileReader(File)

FileSystem.OpenTextFileReader(File, Encoding)


Parameters


File

String, input



File to read.


Encoding

Encoding, input



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


Remarks


Encoding



ASCII

Gets an encoding for the ASCII (7-bit) character set.


Unicode

Gets an encoding for the UTF-16 format using the little endian byte order.


UTF32

Gets an encoding for the UTF-32 format using the little endian byte order.


UTF7

Gets an encoding for the UTF-7 format.


UTF8

Gets an encoding for the UTF-8 format.



StreamReader Properties



EndOfStream (Boolean)

Gets a value that indicates whether the current stream position is at the end of the stream.


StreamReader Methods



Close()

Closes the StreamReader object and the underlying stream, and releases any system resources associated with the reader.


Peek()

Returns the next available character, but does not consume it.


Read()

Reads the next character from the input stream and advances the character position by one.


ReadLine()

Reads a line of characters from the current stream and returns the data as a string.


ReadToEnd()

Reads all characters from the current position to the end of the stream.


Examples

This example opens the specified file, reads a line from it and displays the line in a message box:


Sub Main()

fileReader = FileSystem.OpenTextFileReader("C:\Users\Public\My Directory\Test.txt")

stringReader = fileReader.ReadLine()

MsgBox("The first line of the file is:" & vbCrLf & vbCrLf & stringReader)

End Sub


This example specifies Unicode encoding:


Sub Main()

fileReader = FileSystem.OpenTextFileReader("C:\Users\Public\My Directory\Test.txt", Encoding.Unicode)

stringReader = fileReader.ReadLine()

MsgBox("The first line of the file is:" & vbCrLf & vbCrLf & stringReader)

End Sub