Opposite of slurp. Opens f with writer, writes content, then
closes f. Options passed to clojure.java.io/writer.
user=> (spit "event.log" "test 1\n" :append true) nil user=> (spit "event.log" "test 2\n" :append true) nil user=> (println (slurp "event.log")) test 1 test 2 nil
(defn append-to-file "Uses spit to append to a file specified with its name as a string, or anything else that writer can take as an argument. s is the string to append." [file-name s] (spit file-name s :append true))
(defn spit
"Opposite of slurp. Opens f with writer, writes content, then
closes f. Options passed to clojure.java.io/writer."
{:added "1.2"}
[f content & options]
(with-open [#^java.io.Writer w (apply jio/writer f options)]
(.write w (str content))))
Comments top
No comments for spit. Log in to add a comment.