Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing CSV file in Clojure with writer

I need to return from the server a CSV file.

I have the data which is a simple map, I DO NOT want to create a file on the disk, I saw that the write-csv function can accept as argument a writer.

Something like that (but it doesnt work):

(csv/write-csv (java.io.BufferedWriter. (java.io.OutputStream.  )) csv-data)

The error:

:cause java.io.OutputStream
 :via
 [{:type java.lang.InstantiationError
   :message java.io.OutputStream
like image 477
Benny67b Avatar asked Sep 15 '25 12:09

Benny67b


1 Answers

If you just want a string, you could use with-out-str:

(with-out-str
  (csv/write-csv *out* csv-data))
like image 150
Svante Avatar answered Sep 18 '25 06:09

Svante