OPENREAD

Synopsis
OPENREAD filename
(OPENREAD filename binarymode)
Description

Opens the file named filename for reading. The read position is initially at the beginning of the file.

If the filename input is the reserved word "clipboard, then any text data on the clipboard can be read as if it were in a file. If the clipboard is opened in binary mode, then the clipboard's contents are encoded in UTF-8. Even in binary mode, only text data can be read from 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, OPENREAD infers the character encoding from the Unicode signature, a byte order mark (BOM) that is at the beginning of the file. OPENREAD only recognizes two Unicode character encodings: UTF-8 and UTF-16LE. If a Unicode signature is recognized, it is excluded from the characters that are read from the file. If there is no Unicode signature or if the Unicode signature is not recognized, then the file is assumed to be encoded in the system default Windows code page. In addition, when reading from a text file, the end-of-line sequence is converted from CRLF to LF.

When reading from a binary file, the data is read as bytes (values from 0 - 255) and no end-of-line sequence conversion is performed. If a Unicode signature is present, it is included in the data that is read from the file as a sequence of bytes.

OPENREAD throws an error if no file named filename exists or if the file cannot be opened for reading.

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