【发布时间】:2014-02-28 18:12:46
【问题描述】:
我正在使用 SML 中的一些输入/输出功能,我想知道是否可以将特定内容从一个文件复制到另一个文件,而不是复制整个内容?
假设我在其中一个文本文件中有一个返回整数列表的函数,我只想将此结果列表复制到空输出文件中。如果这是可能的,我如何应用我的 copyFile 函数将列表自动复制到输出文件?
这是我用来将整个文本从一个文件复制到另一个文件的函数:
fun copyFile(infile: string, outfile: string) =
let
val In = TextIO.openIn infile
val Out = TextIO.openOut outfile
fun helper(copt: char option) =
case copt of
NONE => (TextIO.closeIn In; TextIO.closeOut Out)
| SOME(c) => (TextIO.output1(Out,c); helper(TextIO.input1 In))
in
helper(TextIO.input1 In)
end
【问题讨论】: