可以使用WITH-OPEN-FILE宏打开文件以作为流写入。
(with-open-file (file #P"test.file" :direction :output :if-exists :append :if-does-not-exist :create) (dolist (line '("Foobar" "Barfoo" "Quuxbar" "Barquux" "Quuxfoo" "Fooquux")) (write-line line file)))
可以使用OPEN和手动进行相同操作CLOSE。
(let ((file (open #P"test.file" :direction :output :if-exists :append :if-does-not-exist :create))) (dolist (line '("Foobar" "Barfoo" "Quuxbar" "Barquux" "Quuxfoo" "Fooquux")) (write-line line file)) (close file))