Erlang - file_read



There is a method available to allow the reading of all the contents of a file at one time. This is done with the file_read method. The details of this command are as follows.

Syntax

file_read(filename)

Parameters

  • filename − This is name of the file which needs to be read.

Return Value

The entire contents of the file.

For example

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

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

Output

When we run the above program, we will get the following result.

{ok,<<"Example1\nExample2\nExample3">>}
erlang_file_input_output.htm
Advertisements