Erlang-file-read

提供:Dev Guides
移動先:案内検索

Erlang-file_read

ファイルのすべての内容を一度に読み取ることができる方法があります。 これはfile_readメソッドで行われます。 このコマンドの詳細は次のとおりです。

構文

file_read(filename)

パラメーター

  • ファイル名-これは読み取る必要があるファイルの名前です。

戻り値

ファイルの内容全体。

例えば

-module(helloworld).
-export([start/0]).

start() ->
   Txt = file:read_file("Newfile.txt"),
   io:fwrite("~p~n",[Txt]).

出力

上記のプログラムを実行すると、次の結果が得られます。

{ok,<<"Example1\nExample2\nExample3">>}