你应该关闭*out*
(标准输出)吗?例如,通过with-open
宏:
(require '[clojure.java.io :as io])
(with-open [w (io/writer *out*)]
(.write w "foo"))
如果我通过Leiningen' s(v2.7.0)lein run
运行此操作,我会遇到例外:
Exception in thread "main" java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:45)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:140)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at clojure.core$flush.invokeStatic(core.clj:3691)
at clojure.main$main.invokeStatic(main.clj:423)
at clojure.main$main.doInvoke(main.clj:386)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
否则,代码工作正常。