open(FileName,Mode,Stream):
Opens a file for input or output, as indicated by I/O mode Mode and the list of stream-options Options. If it succeeds in opening the file, it unifies Stream with the stream identifier of the associated stream. If FileName is already opened, this predicate unifies Stream with the stream identifier that is already associated with the opened stream, but does not affect the contents of the file.
An I/O mode is one of the following atoms:
- read - Input. FileName must be the name of a file that already exists.
- write - Output. If the file that is identified by FileName already exists, then the file is emptied; otherwise, a file with the name FileName is created.
- append - Output. This is similar to write, except that the contents of a file will not be lost if the file already exists.
The list of stream-options is optional. The list can either be empty, or it can include8.1:
- type(text) or type(binary). The default is type(text). This option does not have any effect on file manipulations.
- alias(Atom). Gives the stream the name Atom. A stream-alias can appear anywhere that a stream can occur. A stream can be given multiple names, but an atom cannot be used as the name of more than one stream.
- eof_action(Atom). Specifies what to do upon repeated attempts to read past the end of the file. Atom can be8.2:
- error - raises an error condition.
- eof_code (the default) - makes each attempt return the same code that the first attempt returned (-1 or end_of_file).