参考文档:
《Programming Erlang》,第13章:Programming with Files
官方文档, 、和。
示例:
%% 文件读写示例-module(file_example).-export([write/2, read/1]).%% --------------------%% 写入文件%% write(Content, FileName) -> {ok, Content}%% Content = string()%% FileName = string()%% --------------------write(Content, FileName) when is_list(Content); is_list(FileName) -> FileAbsolutePath = lists:append([get_local_path(), "/", FileName]), {ok, IoDevice} = file:open(FileAbsolutePath, [append]), io:format(IoDevice, "~s", [Content]), file:close(IoDevice), {ok, Content}.%% --------------------%% 读取文件%% read(FileName) -> binary()%% FileName = string()%% --------------------read(FileName) when is_list(FileName) -> {ok, Content} = file:read_file(FileName), Content.get_local_path() -> filename:dirname(code:which(?MODULE)).