how to read the contents of a file In Erlang ?

Posted by Zubair on Stack Overflow See other posts from Stack Overflow or by Zubair
Published on 2010-03-19T06:01:35Z Indexed on 2010/03/19 7:31 UTC
Read the original article Hit count: 119

Filed under:

I know you can do something like this:

readlines(FileName) ->
    {ok, Device} = file:open(FileName, [read]),
    get_all_lines(Device, []).

get_all_lines(Device, Accum) ->
    case io:get_line(Device, "") of
        eof  -> file:close(Device), Accum;
        Line -> get_all_lines(Device, Accum ++ [Line])
    end.

: Is there a one liner BIF that can do this too?

© Stack Overflow or respective owner

Related posts about erlang