Erlang文件追加模式

Erlang文件追加模式

本文介绍了Erlang文件追加模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 语法ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax ax使用:file:write_file(/ tmp / test1.txt,Abhimanyu,append)。 
错误:{error,badarg}

谢谢

解决方案

在不要创建它如果不存在的附加问题,你必须通过使用类似的文件更有创意:file_info: / p>

 案例文件:
{ok,FileInfo}的read_file_info(FileName)
文件:write_file(FileName,Abhimanyu,[append]);
{error,enoent} - >
%文件不存在
donothing
end。

追加模式(或写入模式)将创建文件(如果不存在)


I m trying to write some content in file using append mode in erlang but it giving error as bad argument.

Syntax used: file:write_file("/tmp/test1.txt","Abhimanyu","append").
error:{error,badarg}

thank you

解决方案

On the "don't create it if it doesn't exist" additional question, you have to be more creative by using something like file:read_file_info :

 case file:read_file_info(FileName) of
        {ok, FileInfo} ->
                 file:write_file(FileName, "Abhimanyu", [append]);
        {error, enoent} ->
                 % File doesn't exist
                 donothing
 end.

The append mode (or write mode) will create the file if it doesn't exist...

这篇关于Erlang文件追加模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:51