[id] = OpenFile(id, filename$[, mode, table])
idto it. If you pass Nil in
OpenFile()will automatically choose a vacant identifier and return it. If the file does not exist, this function will fail unless you use the
modeargument to open a file for writing. In that case,
OpenFile()will create the file for you.
All read and write operations will start at the current file cursor position. You can manually set the file cursor by using the Seek() function but it is also increased if you use other functions which read from or write to the file.
Starting with Hollywood 2.0 you can use the optional argument
open the file in read (default) or write mode or in shared mode, which
means that you can read from the file and you can also write to it. If
a file is opened in read mode, all write operations will fail. If a file
is opened in write mode, all read operations will fail.
Starting with Hollywood 6.0 this function accepts an optional table argument which can be used to pass additional parameters. The following table elements are currently recognized:
default. See Loaders and adapters for details. (V6.0)
#ENCODING_ISO8859_1and Hollywood will handle all conversions to and from ISO 8859-1 automatically. See SetDefaultEncoding for a list of available charsets. (V9.0)
Trueif you want
OpenFile()to add the UTF-8 BOM (byte order mark) to the beginning of the file. Obviously,
OpenFile()will only do this if the file has been opened in write mode (
#MODE_WRITE) and the file's encoding has been set to
Although Hollywood will automatically close all open files when it quits, it is strongly advised that you close an open file when you are done with it using the CloseFile() function so that it becomes available to the operating system again.
Starting with Hollywood 9.0,
filename$ may also be one of the special
#STDERR. This is useful for advanced
programmers who want to access the
streams associated with each program.
This command is also available from the preprocessor: Use @FILE to preopen files.
OpenFile(1, "Highscores.txt") While Not Eof(1) Do NPrint(ReadLine(1)) CloseFile(1)This code opens the file "Highscores.txt" as file 1 and prints all of its lines to the screen.