FileWriter Objects |
Active Web |
A FileWriter object is used to write to a text file on the script server. For non text files use the BinaryFile object.
FileWriter objects are of class FileWriter.
Property |
Description |
error |
An error message If an error has occurred. If no error has occurred then it will be null. The error messages are explained below: File not accessible - The file specified by the name does not exist. No write access for file - The file specified by the name can not be written. This could be because the file does not exist or because we do not have permission to write to it. Encoding not found - The encoding specified in the constructor is not a recognized encoding. This means that you will not be able to write to this file. File error - The file had an error while opening. While accessing the file the operating system can generate various other error messages. |
prototype |
A reference to the Object Prototype. This property does not enumerate and can not be deleted but can be changed. |
Function |
Description |
close() |
Closes the file and frees resources. If an error occurs then this function returns false. If the close is successful then this function returns true. |
write(string) |
Writes the string to the file. If an error occurs then this function returns false and the error property will be set. If the string is written successfully then this function returns true. |
writeln(string) |
Writes the string to the file followed by a new line character. If an error occurs then this function returns false and the error property will be set. If the string is written successfully then this function returns true. |
The FileWriter constructor is used to create new FileWriter objects.
var myFileWriter = new FileWriter(name[, mode[, encoding]]);
A new FileWriter object for the file identified by the name is created. The name uses the script file reference to identify the file. The file can be anywhere on the host filing system. If the name argument is not present then a runtime error will be generated and the script page execution halted.
The mode determines whether the write replaces any existing file or appends data to an existing file. To replace set the mode to "w" and to append set the mode to "a". The mode has no effect if the file does not already exist. Default is Replace.
The encoding argument identifies the encoding required to read the file. If this argument is not present then the default script encoding (defined in the Active Web console) is used.
Shown below is the FileWriter object prototype chain.
When the constructor is run as a function without the new operator it has exactly the same behaviour as using the new operator.
Constructor properties are read only (they can not be changed or deleted) and it is not possible to add new properties to the Constructor.
Property |
Description |
prototype |
A reference to the Object Prototype. This property does not enumerate and can not be changed or deleted. |
The FileWriter constructor has no predefined functions.
Topic ID: 150053