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
