This predicate opens a source/sink which is a text stream with the default options,
these default options are: type(text), reposition(false), eof_action(error). These options
mean: a text stream of which the stream position cannot be repositioned and if input is
read past the end of the stream then an error exception is thrown.
The first parameter is the location of the source/sink, if the location contains backslash
characters then be sure to replace each single backslash character with two backslash
characters, for instance: if the file to open is 'c:\temp\test.txt' then the value of the
first parameter must be 'c:\\temp\\test.txt' (see also escape
sequences).
The second parameter must be one of the following predefined atoms:
If a stream was successfully opened then the third parameter '-stream' is assigned a non atomic ground term.
see also: at_end_of_stream/0 at_end_of_stream/1 close/1 close/2 close_user_streams/0 current_input/1 current_output/1 flush_output/0 flush_output/1 open/4 prolog I/O set_input/1 set_output/1 set_stream_position/2 set_stream_property/2 stream_property/2
| Example | |
| open('c:\\temp\\input.txt', read, Stream). | if there is a file at the location 'c:\temp\input.txt then it was successfully opened and Stream was assigned the value '$stream(3)', if there are no other streams except the standard streams |
| Exceptions | |
| source_sink is a variable | an instantiation_error exception is thrown |
| source_sink is neither a variable nor a source/sink term | a domain_error(source_sink, SourceSink) exception is thrown, variable SourceSink is substituted by the incorrect source/sink term |
| the source/sink specified by SourceSink does not exist | an existence_error(source_sink, SourceSink) exception is thrown |
| the source/sink specified by SourceSink cannot be opened | a permission_error(open, source_sink, SourceSink) exception is thrown |
| io_mode is a variable | an instantiation_error exception is thrown |
| io_mode is neither a variable nor an atom | a type_error(atom, IOMode) exception is thrown |
| io_mode is an atom but not an I/O mode | a domain_error(io_mode, IOMode) exception is thrown |
| Stream is not a variable | a type_error(variable, Stream) exception is thrown |