• (spit f content & options)
Opposite of slurp. Opens f with writer, writes content, then
closes f. Options passed to clojure.java.io/writer.

3 Examples top

  • user=> (spit "flubber.txt" "test")
    nil
    user=> (slurp "flubber.txt")
    "test"
  • 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))
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:6032 top

(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))))
Vars in clojure.core/spit:
Used in 0 other vars

Comments top

No comments for spit. Log in to add a comment.