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 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 identified by FileName
already exists, then the file is emptied; otherwise, a file with the name
FileName is created.
- append - Output. Similar to write except that the contents
of a file will not be lost if it already exists.
The list of stream-options is optional and can be empty or a list
that includes5.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 a name Atom. A stream-alias
can appear anywhere a stream can occur. A stream can be given multiple
names, but an atom cannot be used as names of multiple streams.
- eof_action(Atom). Specifies what to do upon repeated
attempts to read past the end of the file. Atom can be5.2:
- error - raises an error condition.
- eof_code (the default)- makes each attempted return the same
code that the first one did ( -1 or end_of_file).