Opens a reader on f and reads all its contents, returning a string.
See clojure.java.io/reader for a complete list of supported arguments.
;; To access web page. Note the use of http:// ;; prefix user=> (slurp "http://clojuredocs.org") ; This will return the html content of clojuredocs.org
;; On Linux, some JVMs have a bug where they cannot read a file in the /proc ;; filesystem as a buffered stream or reader. A workaround to this JVM issue ;; is to open such a file as unbuffered: (slurp (java.io.FileReader. "/proc/cpuinfo"))
(defn slurp
"Opens a reader on f and reads all its contents, returning a string.
See clojure.java.io/reader for a complete list of supported arguments."
{:added "1.0"}
([f & opts]
(let [opts (normalize-slurp-opts opts)
sb (StringBuilder.)]
(with-open [#^java.io.Reader r (apply jio/reader f opts)]
(loop [c (.read r)]
(if (neg? c)
(str sb)
(do
(.append sb (char c))
(recur (.read r)))))))))
Comments top
No comments for slurp. Log in to add a comment.