Reputation: 13
I have read the file as follows
(defn get-lines [file]
(with-open [rdr (clojure.java.io/reader file)]
(count (line-seq rdr))))
(get-lines "D:/clojurefile/t2/ct.txt")
but it does not display the content I want to print the data in my file on prompt!
Upvotes: 0
Views: 312
Reputation: 5395
(count (line-seq rdr))
returns the number of lines in the file. You should remove count
to have the entire contents of the file printed:
(defn get-lines [file]
(with-open [rdr (clojure.java.io/reader file)]
(line-seq rdr)))
(println (get-lines "D:/clojurefile/t2/ct.txt"))
Edit: to print the contents of the file from command line (rather that in the REPL) you should use a print function - edited above. Also, if the file is not too large, it will be simpler to use the slurp
function, which reads the file's contents in the memory at once, instead of with-open
:
(println (slurp "D:/clojurefile/t2/ct.txt"))
Upvotes: 1