title: Prolog - unexpected end of file
body: <h1>Reading a file in Prolog error</h1>
  <p>Hi, I'm working on a Prolog project and I need to read the whole file in it. I have a file named 'meno.txt' and I need to read it. I found some code here on stack. The code is following:</p>
  <pre><code>main :-
    open('meno.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).
  </code></pre>
  <p>When I call the <code>main/0</code> predicate, I get an error saying unexpected end of file. My file looks like this:</p>
  <pre><code>line1
  line2
  line3
  line4
  </code></pre>
  <p>I also found the similar problem here and the solution where in ASCII and UTF coding but I tried that and it seems its not my solution. Can anyone help?</p>