Tabular IQ

TextWriter Class

Class Index By Category

Overview

The TextWriter class represents a file access stream for writing text data to a text file.

Methods

TextWriter.write
Writes text to a text file
TextWriter.writeLine
Writes a single line to a text file

Example

// the file this example creates, in the system's temporary directory
// (Environment.getTempPath() does not include a trailing separator)
const path = `${Environment.getTempPath()}/testfile.txt`;

// try to create a text file
const writer = File.createText(path);
if (writer) {
    writer.writeLine("Line 1");
    writer.writeLine("Line 2");
    writer.writeLine("Line 3");

    // write() adds no line ending, so these three calls all land
    // on the same line
    writer.write("Line 4");
    writer.write(" - still on line 4");
    writer.writeLine(" - still on line 4");

    writer.writeLine("Line 5");

    // close() flushes the file to disk
    writer.close();

    alert(`Wrote ${path}`);
}

TextWriter.write

function TextWriter.write(text : String) : Boolean

Returns

True if the function succeeded, false upon failure.

Description

Write a single line to a file, but does not add any carriage return or line feed.

TextWriter.writeLine

function TextWriter.writeLine(text : String) : Boolean

Returns

True if the function succeeded, false upon failure.

Description

Write a single line to a file, ending it with a newline. The platforms text file format is respected, so on Windows systems, a carriage return and a line feed are added, but on Linux systems, only a newline character is added.