liveBook · Manning

Clojure.java.io/reader

As explained in Clojure: The Essential Reference

clojure.java.io/reader is a polymorphic Clojure function that creates a character reader from supported resource, stream, file, URL, socket, array, or string inputs.

clojure.java.io/reader creates a java.io.BufferedReader while hiding the conversions among Java I/O abstractions. It accepts readers, streams, files, URLs, sockets, arrays, and strings; strings are interpreted as locations rather than text. section 22.8

Use the reader with ordinary Clojure sequence and resource-management tools:

  • Wrap it in with-open so the operating-system resource is closed after processing. section 22.8

Count lines in a file

(with-open [r (io/reader "/usr/share/dict/words")] (count (line-seq r))) ;; 235886

How Clojure: The Essential Reference covers it

How deep it goes
Explains supported inputs, resource closure, string-location behavior, and encoding options, without detailing implementation internals.
Examples
Demonstrates counting file lines and reading literal string content through a character array.
What it assumes
Assumes basic Clojure forms and Java I/O awareness while demonstrating resource management and polymorphic input conversion.
What you can do after
Operate/configure readers for files or character data, process lines, consume content, and close resources safely.
How it connects
Connects Java I/O streams, BufferedReader, with-open, line-seq, slurp, files, URLs, and character arrays.

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.