You're viewing version 1.2.0 of reader. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (reader x & opts)
Attempts to coerce its argument into an open java.io.Reader.
Default implementations always return a java.io.BufferedReader.

Default implementations are provided for Reader, BufferedReader,
InputStream, File, URI, URL, Socket, byte arrays, character arrays,
and String.

If argument is a String, it tries to resolve it first as a URI, then
as a local file name. URIs with a 'file' protocol are converted to
local file names.

Should be used inside with-open to ensure the Reader is properly
closed.

2 Examples top

  • (with-open [rdr (clojure.java.io/reader "/tmp/foo.txt")]
        (reduce conj [] (line-seq rdr)))
  • user=> (with-open [rdr (clojure.java.io/reader "http://www.google.com")]
             (printf "%s\n" (clojure.string/join "\n" (line-seq rdr))))
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/java/io.clj:80 top

(defn ^Reader reader
  "Attempts to coerce its argument into an open java.io.Reader.
   Default implementations always return a java.io.BufferedReader.

   Default implementations are provided for Reader, BufferedReader,
   InputStream, File, URI, URL, Socket, byte arrays, character arrays,
   and String.

   If argument is a String, it tries to resolve it first as a URI, then
   as a local file name.  URIs with a 'file' protocol are converted to
   local file names.

   Should be used inside with-open to ensure the Reader is properly
   closed."
  {:added "1.2"}
  [x & opts]
  (make-reader x (when opts (apply hash-map opts))))
Vars in clojure.java.io/reader: apply defn hash-map when
Used in 0 other vars

Comments top

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