← All Articles

How to Read a file in Elixir

Posted on

Reading files in elixir is pretty straight forward - especially if you just want the content of a file you know exists. And that case it is a oneliner just like in php.

defmodule Test do

  def echo() do
    IO.write(File.read!("file.ex"))
  end


end

Test.echo()

There is a lot more to files in elixir though. Be sure to read the documentation for the specifics.

polyglotbitselixirread-a-file