File reading fun with Elixir and Erlang
To read a file using Elixir File module, all you gotta do is this (if you fire up your iex, and run this - assuming you have your file in the proper location)
In Elixir
{:ok, wf} = File.read "c:\\tmp\\test2.log"
What if you wanted to write. In that case, we need to open our file using the command below and assigned file handler to a variable called "wf".
{:ok, wf} = File.open "c:\\tmp\\test3.log"
To write to your already open file handler.
IO.binwrite wf, "uhh llalala"
Using Erlang
:file.read_file("c:\\tmp\\test2.log")
This also gives us a clue to call Erlang's built in libraries.
Comments