Search code examples

How to use in Clojure?

(import java.nio.file.Files)
(import java.nio.file.Paths)

(def path 
  (Paths/get "." 
    (into-array ["data" "10000000.test.log"])))

(def stream 
  (Files/lines path))

This way I have:

#object[$Head 0x50129b8f

Is there a way to iterate over this without running out of memory? The suggestion on SO are not really helpful. The files is ~1G.


  • I wanted to iterate over the stream Java / imperative style to avoid blowing up the heap. I do not need to reduce on the stream, I need to process every line and take out one field and send it out. I think for this I probably better off with doseq.

      [l (iterator-seq (.iterator stream))] 
        (println l))