How to implement “appendFile” function?

后端 未结 2 954
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 20:45

I can use the following function to overwrite a text file:

let writeFile ~filename:fn s =
let oc = open_out fn in
    output_string oc s;
    close_out oc ;;         


        
2条回答
  •  遥遥无期
    2021-01-14 21:03

    You could pass additional mode flag Open_append to open_out_gen function:

    let _ =
        let oc = open_out_gen [Open_creat; Open_text; Open_append] 0o640 "a.txt" in
        output_string oc "append\n";
        close_out oc
    

提交回复
热议问题