You can use read
to read the stream. Remember to invoke at_end_of_stream
to ensure no syntax errors.
Example:
readFile.pl
main :-
open('myFile.txt', read, Str),
read_file(Str,Lines),
close(Str),
write(Lines), nl.
read_file(Stream,[]) :-
at_end_of_stream(Stream).
read_file(Stream,[X|L]) :-
+ at_end_of_stream(Stream),
read(Stream,X),
read_file(Stream,L).
myFile.txt
'line 0'.
'line 1'.
'line 2'.
'line 3'.
'line 4'.
'line 5'.
'line 6'.
'line 7'.
'line 8'.
'line 9'.
Thus by invoking main
you will recieve the output:
?- main.
[line 0,line 1,line 2,line 3,line 4,line 5,line 6,line 7,line 8,line 9]
true
Just configure main
. The output here is an example by using write
, of course. Configure to match your request.
I assume that this principle can be applied to answer your question. Good luck.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…