# OPEN

OPEN File name FOR [ READ ] [ WRITE ] [ CREATE | APPEND ] [ DIRECT ] [ WATCH ] [ BIG | LITTLE ] AS # Variable

Opens a file for reading, writing, creating or appending data. The file must exist, unless the CREATE keyword is specified.

If the CREATE keyword is specified, then the file is created, or cleared if it already exists.

If the APPEND keyword is specified, then the file pointer is moved to the end of file just after the file is opened.

If the DIRECT keyword is specified, the input-output are not buffered.

If the WATCH keyword is specified, the file is watched by the interpreter :

- If at least one byte can be read from the file, then the event handler `File_Read()` is called.
- If at least one byte can be written into the file, then the event handler `File_Write()` is called.

If the BIG or LITTLE keyword is specified, then all subsequent READ and WRITE operations on this file will use big-endian or little-endian data representation.

The variable receives the object that represents the opened stream.

Example

    ' Watching a serial port

    DIM hFile AS File

    OPEN "/dev/ttyS0" FOR READ WRITE WATCH AS #hFile

    ...

    PUBLIC SUB File_Read()

      DIM iByte AS Byte

      READ #hFile, iByte
      PRINT "Got one byte: "; iByte

    END

    ' Reading data from a BMP file, known to use little-endian format :

    DIM hFile AS File
    DIM iData AS Integer

    OPEN "./image.bmp" FOR READ LITTLE AS #hFile
    ...
    READ #hFile, iData

See also

CLOSE, COPY, Eof, FLUSH, INPUT, Lof, LINE INPUT, KILL, PRINT, READ, RENAME, Seek, SEEK, WRITE

Previous: NULL Next: OR