haskell读写文件相关(含二进制)


使用System.IO模块

使用函数

openBinaryFile :: FilePath -> IOMode -> IO Handle

打开文件 IOMode为 ReadWriteMode, 不然会截断文件

eg:

h <- openFile "b.txt" ReadWriteMode
hPutChar h 'b'
hPutChar h 'b'
hPutChar h 'b'
hPutChar h 'b'
hPutChar h 'b'
hClose h

如果处理二进制文件

要引入模块Data.ByteString

hPut :: Handle -> ByteString -> IO ()

Outputs a ByteString to the specified Handle.

===========================

库文档路径

https://downloads.haskell.org/~ghc/7.6-latest/docs/html/libraries/index.html

 

posted @ 2015-09-25 14:18  zhao1949  阅读(579)  评论(0编辑  收藏  举报