This predicate opens a text stream, with the default options, and makes it the current input stream. If the parameter is a filename then make 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 file to open must exist.
The default options for text streams are: type(text), reposition(false), eof_action(error). These options mean: a text stream of which the stream position cannot be repositioned and an error exception is thrown if input is read past the end of the stream.
If the value of the parameter is 'user' or 'user_input' then the standard input stream is made the current input stream. If the stream was successfully opened then the predicate succeeds else it fails. This predicate is not defined in the ISO Prolog standard.
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/1open/3 open/4 prolog I/O set_input/1 set_output/1 set_stream_position/2 stream_property/2
| Example | |
| see('c:\\temp\\input.txt'). | if there is a file at the location 'c:\temp\input.txt' then it was successfully opened and made the current input stream |
| see(user). | the standard input stream becomes the current input stream |
| see(user_input). | the standard input stream becomes the current input stream |
| Exceptions | |
| Source is a variable | an instantiation_error exception is thrown |
| Source is neither a variable nor a source/sink term | a domain_error(source_sink, Source) exception is thrown, variable Source is substituted by the incorrect source term |
| the source specified by Source does not exist | an existence_error(source_sink, Source) exception is thrown |
| the source specified by Source cannot be opened | a permission_error(open, source_sink, Source) exception is thrown |