The TextWriter class represents a file access stream for writing text data to a text file.
// 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}`);
} True if the function succeeded, false upon failure.
Write a single line to a file, but does not add any carriage return or line feed.
True if the function succeeded, false upon failure.
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.