我给定的文件/path/file.txt 包含例如以下内容:
Hello World!
Try to read me.
如何阅读 整个 内容到一单我的代码中的字符串?
对于此特定示例,字符串应如下所示:
"Hello World!\nTry to read me."
最佳答案
如果您不想使用 Core,则以下内容适用于内置 Pervasives 模块中的函数:
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
关于ocaml - 如何将给定文件的全部内容读入字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53839695/