【发布时间】:2013-05-16 02:01:32
【问题描述】:
我正在尝试让一个程序使用 hFlush 读取整个文件,以避免我遇到的与惰性 IO 相关的问题。
readHandle <- openFile fileName ReadMode
hSetBuffering readHandle $ BlockBuffering (Just 2048)
fileText <- hGetContents readHandle
hFlush readHandle
hClose readHandle
这只是给了我错误:hFlush: 非法操作(句柄已关闭)
有人可以帮我了解发生了什么
【问题讨论】:
-
另外,
hFlush刷新 输出 缓冲区。首先在只读句柄上使用它没有任何意义。 -
我推荐使用
hGetContentsfromSystem.IO.Strict并完全避免使用惰性 IO。
标签: haskell io lazy-evaluation