Wikibooksβ

Prolog/Input and Output

Filenames must be put between apostrophes, so they become atoms. ( "foo.txt" will not work, because it's a list of characters and not an atom.) In Windows systems you can write paths as 'C:/foo.txt' or 'C:\\foo.txt'.

You can have multiple files open at the same time: If you use see(file1) and then see(file2), you will have 2 open files at the same time, and if you now call get_char, it will read from file2. If you call see(file1) again, file1 will be active again. You can close these files in any order you want.

The read predicate is for parsing prolog terms. (It can handle DCG grammars as well.) You might need it for self-modifying programs, or for programs which transforms prolog code.