I’m trying to read a file line by line, but I don’t know how to stop when I reach the EOF.
I have this code:
readWholeFile = do inputFile <- openFile "example.txt" ReadMode
readALine inputFile
readALine x = do y <- hGetLine x
print y
readALine x
and it obviously always terminata raising an exception.
How can I solve?
Edit: exact error message is:
*** Exception: example.txt: hGetLine: end of file
What you are looking for is, hIsEOF
Check out http://book.realworldhaskell.org/read/io.html