clojure.java.io/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.
Examples¶
Note by roryokane¶
Java documentation links for the listed argument types that have “default implementations�:
ReaderBufferedReaderInputStreamFileURIURLSocket- byte arrays (
byte[]) - character arrays (
char[]) String(resolved as a URI or a local file name)
Note by jakubholynet¶
opts depend on the type of the reader but common ones include :encoding and, where applicable, :buffer-size.
Note by KingMob¶
Warning, it does not work with java.nio.file.Path (as of 1.11.1).
See also¶
- clojure.java.io/writer (1)
- clojure.java.io/input-stream
- clojure.java.io/IOFactory
- clojure.core/slurp (2)
Content from the matching ClojureDocs page, with authors credited on each contribution.