2011-11-04 38 views
2

我想讀取文本文件並將其作爲序列並傳遞給它。我怎麼做?從Common Lisp的文本文件中讀取序列

這是我到目前爲止有:

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

的文本文件是這樣的:

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

回答

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