File input/output: Difference between revisions

m
m (→‎{{header|Wren}}: Changed to Wren S/H)
Line 3,775:
 
=={{header|Standard ML}}==
===Reading the whole file at once as a string===
{{works with|SML/NJ|110.59}}
{{works with|Poly/ML|5.9.1}}
<syntaxhighlight lang="sml">fun copyFile (from, to) =
(* string -> string -> bool *)
fun copyFile from to =
let
val instream = TextIO.openIn from
Line 3,785 ⟶ 3,789:
in
true
end handle _ => false;</syntaxhighlight>
===Binary mode using a buffer===
{{works with|Poly/ML|5.9.1}}
{{works with|SML/NJ|110.99.4}}
<syntaxhighlight lang="sml">
fun copyFile from to =
let
val instream = BinIO.openIn from
val outstream = BinIO.openOut to
fun aux () =
let
val buf = BinIO.inputN(instream, 1024)
in
if Word8Vector.length buf = 0
then ()
else (BinIO.output (outstream, buf); aux ())
end
in
(aux (); BinIO.closeIn instream; BinIO.closeOut outstream)
end
</syntaxhighlight>
 
=={{header|Stata}}==
23

edits