How to implement “appendFile” function?

后端 未结 2 952
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  梦毁少年i
    2021-01-14 20:59

    This is what I do:

    let append_string path s =
        let chan = open_out_gen [Open_wronly; Open_creat] 0o666 path
        in let len = out_channel_length chan
        in
            begin
            seek_out chan len;
            output_string chan s;
            close_out chan;
            end
    

提交回复
热议问题