File.write()

NES2+Syntax

							file.write(string)

Description

The write() method of the File object writes the string passed to the method to the file on which it was invoked. The method returns true if it was successful and false otherwise. You should use the read() or readln() methods to read any string information from other files that you want to write. If you need to write binary information, use the writeByte() method.

Example

Listing 8.87 writes "Hello, World!" to the summary file opened.

Listing 8.87 Using write() to Write a String to a File
 <SERVER> // Set an instance of a File var mySummary = new File("/data/logs/summary.log"); // Open the log file for writing mySummary.open("w"); // Write a string to the file mySummary.write('Hello, ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.