erlang file 追加写

本文介绍如何在Erlang中进行文件操作,特别是如何避免每次读取时覆盖文件内容,重点讨论file:open函数的参数设置,以实现文件的追加写入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

erlang 进行文件操作

{ok, Write} = file:open("test.txt",[write]),
io:format(Write, "~s", ["string"] ).

但是这样做每次读都会覆盖文件内容


{ok, Write} = file:open("test.txt",[<span style="color:#FF0000;">append</span>]),
io:format(Write, "~s", ["string"] ).

这样就可以追加

其实知识在

file:open的参数里有。。不过有时候真心翻着麻烦


write

    The file is opened for writing. It is created if it does not exist. If the file exists, 
    and if write is not combined with read, the file will be truncated.

append

    The file will be opened for writing, and it will be created if it does not exist. 
    Every write operation to a file opened with append will take place at the end of the file.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值