Skip to content

clojure.java.io/reader

View this page on ClojureDocs

Type: function Added: Clojure 1.2 Examples: 3 Runnable: 0
([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.

Examples

by steveminer on . May have evaluation errors.
by jafingerhut on . May have evaluation errors.
by reborg on . May have evaluation errors.

Note by roryokane

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

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


Content from the matching ClojureDocs page, with authors credited on each contribution.