Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement "appendFile" function?

Tags:

ocaml

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 ;;

Howeve, i donot know how to append a line to a text file ?

like image 565
z_axis Avatar asked Jun 22 '26 10:06

z_axis


1 Answers

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
like image 51
barti_ddu Avatar answered Jun 26 '26 17:06

barti_ddu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!