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

Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

A quick tutorial for OWASP ZAP tool for beginners