My given file /path/file.txt contains for example the following:
Hello World!
Try to read me.
How can I read the entire content into one single string inside my code?
For this specific example, the string should look like this:
"Hello World!\nTry to read me."
If you don't want to use Core, the following works with functions from the built-in Pervasives module:
let read_whole_file filename =
let ch = open_in filename in
let s = really_input_string ch (in_channel_length ch) in
close_in ch;
s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With