TextReader - Kirix Documentation

Developer Resources

TextReader

Overview

The TextReader class represents a file access stream for reading text values from a file.

Methods

TextReader.close
Closes the input text file
TextReader.readLine
Read a single line from a text file

Example

var text = "";

// try to open the text file
var reader = File.openText("c:\\testfile.txt");
if (!reader)
{
    alert("Can't open the file.  Does it exist?");
}
else
{
    // file opened successfully;
    // read in all of the lines in the file

    var line;
    while ((line = reader.readLine()) != null)
    {
        text += line;
        text += "\n";
    }

    alert(text);
}

TextReader.close

function TextReader.close() : Boolean

Returns

True if the file was successfully closed, false if the file was not open when close() was invoked.

Description

Closes the input text file. All subsequent calls to readLine() will return null.

TextReader.readLine

function TextReader.readLine() : String

Returns

A string containing the line read from the input text file. If the file is not open, the method returns a null value.

Description

Reads a single line from a text file. The file pointer is automatically advanced to the next line. A string containing the line read is returned, and does not include the carriage return or line-feed character. If the file is not open, a null value is returned.