write( )
Topic group Related topics Example
Writes a character string to a file previously opened with create( ) or open( ). Returns the number of characters written.
Syntax
<oRef>.write(<expC> [, <characters expN>])
<oRef>
A reference to the File object that created or opened the file.
<expC>
The character expression to write to the specified file. If you want to write only a portion of <string expC> to the file, use the <characters expN> argument.
<characters expN>
The number of characters of the specified character expression <string expC> to write to the specified file, starting at the first character in <string expC>. If omitted, the entire string is written.
Property of
File
Description
write( ) writes a character string to a file. If the file was opened in append-only or read and append mode, the string is always added to the end of the file. Otherwise, the string is written starting at the current file pointer position, overwriting any existing characters. You must have either write or append access to use write( ).
write( ) returns the number of bytes written to the file. If write( ) returns 0, no characters were written. Either <expC> is an empty string, or the write was unsuccessful.
Use error( ) to determine if an error occurred.
When write( ) finishes executing, the file pointer is located at the character immediately after the last character written. Use seek( ) to move the file pointer before or after you use write( ).
To write to a text file, use puts( ). puts( ) automatically adds the end-of-line character(s).
To read from a file, use read( ).