You must check zero?before you do read. Please note that your version will call readonce, even if length== 0 to start.
(loop [result "" counter length]
(if (zero? counter)
result
(let [c (char (.read stream))]
(println "=>" c )
(recur (str result c) (dec counter)))))
Another way to avoid the explicit loop:
(apply str
(take length
(repeatedly #(let [c (char (.read stream))]
(println "=>" c) c)))))
source
share