从Common Lisp中的文本文件中读取序列

时间:2011-11-04 21:10:45

标签: file lisp

我想在文本文件中读取并将其作为序列并传递给它。我该怎么做?

这是我到目前为止所做的:

(with-open-file (stream "filename.txt")
  (format t "~a~%" (read-line stream)))

文本文件是这样的:

Hello this is a sentence.
Hello this is second sentence.

1 个答案:

答案 0 :(得分:3)

(with-open-file (in "filename.txt")
  (with-output-to-string (out)
    (loop :for line := (read-line in nil) :while line :do
       (write-line line out)))))
相关问题