ClojureDocs

Nav

Namespaces

reader

clojure.java.io

Available since 1.2
  • (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.
3 Examples
(with-open [rdr (clojure.java.io/reader "/tmp/foo.txt")]
    (into [] (line-seq rdr)))
(with-open [rdr (clojure.java.io/reader "http://www.google.com")]
   (printf "%s\n" (clojure.string/join "\n" (line-seq rdr))))
;; <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" ...
;;=> nil
;; Sometimes it's useful to create a reader from a string, but strings
;; are locations for "reader", so we turn them into char-arrays first:

(require '[clojure.java.io :as io])

(with-open [r (io/reader (char-array "hello"))] (slurp r))
;; "hello"
See Also

Attempts to coerce its argument into an open java.io.Writer. Default implementations always retur...

Added by cgray

Attempts to coerce its argument into an open java.io.InputStream. Default implementations always ...

Added by jafingerhut

Factory functions that create ready-to-use, buffered versions of the various Java I/O stream type...

Added by jafingerhut

Opens a reader on f and reads all its contents, returning a string. See clojure.java.io/reader for...

Added by jafingerhut
3 Notes
    By , created 11.3 years ago

    Java documentation links for the listed argument types that have “default implementations�:

    By , created 9.8 years ago

    opts depend on the type of the reader but common ones include :encoding and, where applicable, :buffer-size.

    By , created 304 days ago

    Warning, it does not work with java.nio.file.Path (as of 1.11.1).