Files and IO
| Read a file | |
| Write a file | |
| Line by line | |
| File errors |
Read a file
The file module reads whole files into binaries. read_file answers {ok, Binary} on success and {error, Reason} when the file is missing. For UTF-8 text the binary is ready for the string functions of lesson 8.
1> file:read_file("todo.txt").
{ok, <<"buy milk">>}
2> file:read_file("missing.txt").
{error, enoent}
Next: Sockets
Article author: Arthur Isaev