TextFileReader Object

Modified on 2010/02/24 22:03 by Administrator — Categorized as: Uncategorized

Facilitates reading from a standard text file.

Accessing files is done under the context of the user that the application or service is running under. This can cause some file permissions/access rights issues if the file does not allow access to that user.


Constructors

none

Instance Properties

EndOfFile

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

Type: Boolean

Example:


eof = file.EndOfStream;

Static Methods

ReadAllText

Opens a file, reads all the text from the file, then closes it.

Syntax:

String ReadAllText(String path)

Parameters:

path: The file to append the specified string to.

Return Value

A string containing all lines of the file.

Example:


s = TextFileReader.ReadAllText("c:\myfiles\names.txt");

OpenText

Opens an existing UTF-8 file for reading.

Syntax:

TextFileReader OpenText(String path)

Parameters:

path: The file to be opened for reading.

Return Value

A TextFileReader for reading.

Example:


file = TextFileReader.OpenText("c:\myfiles\names.txt");

Instance Methods

ReadLine

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

Syntax:

String ReadLine( )

Return Value

The next line from the file, or a empty string if the end of the file is reached.

Example:


file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.ReadLine();

ReadToEnd

Reads the file from the current position to the end of the file.

Syntax:

String ReadToEnd( )

Return Value

The next line from the file, or a empty string if the end of the file is reached.

Example:


file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.ReadToEnd();

Peek

Reads the the next available character but does not consume it.

Syntax:

String Peek( )

Return Value

The next line from the file, or a empty string if the end of the file is reached.

Example:


file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.Peek();

Close

Closes the current file.

Syntax:

void Close( )

Example:


file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.Peek();
file.Close();

See Also

TextFileWriter Object
File System Object
Scripting