OPENWRITE

Synopsis
OPENWRITE filename
(OPENWRITE filename binarymode)
Description

Opens the file named filename for writing. If a file by the given filename already exists, the contents are discarded and OPENWRITE starts with an empty file.

If the filename input is the reserved word "clipboard, then you can write text data to the clipboard as if it were a file. If the clipboard is opened for writing in binary mode, then you must encode the text in UTF-8. Even in binary mode, only text data can be written to the clipboard.

The optional binarymode input is a boolean value (TRUE or FALSE). If binarymode is FALSE or not given, then the file is opened as a text file. If binarymode is TRUE, then the file is opened as a binary file.

When opening a text file, OPENWRITE creates a new file with a UTF-8 BOM. All characters written to the file are encoded in UTF-8. In addition, when writing to a text file, the end-of-line sequence is converted from LF to CRLF.

When writing to a binary file, the data is written as bytes (values from 0 - 255) and no end-of-line sequence conversion is performed.

Example
OPENWRITE "example.txt
SETWRITE "example.txt
PRINT "Hello
PRINT [Good Bye]
SETWRITE []
CLOSE "example.txt

OPENREAD "example.txt
SETREAD "example.txt
REPEAT 2 [SHOW READLIST]
[Hello]
[Good Bye]
SETREAD []
CLOSE "example.txt
See Also
CLOSE

SourceForge.net Logo