liveBook · Manning

Clojure.java.io/writer

As explained in Clojure: The Essential Reference

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

clojure.java.io/writer creates a java.io.BufferedWriter while hiding Java I/O adapter details. It accepts resources, streams, files, URLs, sockets, arrays, and strings, and supports options such as encoding and append. section 22.8

Because I/O objects allocate operating-system resources, bind the writer with with-open so it closes after writing. Use spit for concise output or .write/.append for explicit processing. section 22.8

Write and close a file

(with-open [w (io/writer "/tmp/output.txt")] (spit w "Hello\nClojure!!")) (println (slurp "/tmp/output.txt")) ;; Hello ;; Clojure!! ;; nil

How Clojure: The Essential Reference covers it

How deep it goes
Defines polymorphic inputs, BufferedWriter output, resource closure, encoding, append behavior, and explicit writing without covering implementation internals.
Examples
Demonstrates writing text to a file, transforming dictionary lines, and configuring UTF-16 encoding with append mode.
What it assumes
Assumes basic Clojure forms and introduces the Java Reader/Writer distinction through polymorphic conversions.
What you can do after
Operate/configure it via clojure.java.io to write character data safely to supported destinations.
How it connects
Connects character writers with Reader, InputStream, OutputStream, with-open, spit, slurp, and line-oriented processing.

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.