我想编写一个函数,该函数将两个文件的名称作为参数并将内容从第一个文件复制到第二个文件。
到目前为止,我编写了一个从文件读取的函数:
(defun readFile (name)
(let ((in (open name)))
(format t "~a~%" (read-line in))
(close in)))
还有一个将字符串写入文件的函数:
(defun writeFile (name content)
(with-open-file (stream name
:direction :output
:if-exists :overwrite
:if-does-not-exist :create)
(format stream content)))
按照 Savantes 的说明,我再次编写了该函数,它的外观是这样的:
(defun read-write-to-file (input-file output-file)
(WITH-OPEN-FILE (output-stream output-file
:direction :output
:if-exists :new-version
:if-does-not-exist :create)
(WITH-OPEN-FILE (input-stream input-file
:direction :input)
(FORMAT output-stream "~a" (READ input-stream nil 'eof))
)))
现在唯一的问题是它没有读取整个文件。