Read a Text File using the Standard Library
Task
File System / Files / Read a Text File
No packages used
This recipe uses only the OCaml Standard Library.Code
with_open_text
opens a channel the file at the given path.
input_all
reads all data from the input channel.
These functions can raise Sys_error
exceptions.
let text =
In_channel.(with_open_text "/etc/passwd" input_all)