欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

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

发布时间:2025/5/22 编程问答 23 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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

 

转载于:https://www.cnblogs.com/zhao1949/p/4838066.html

总结

以上是生活随笔为你收集整理的haskell读写文件相关(含二进制)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。