In Clojure 1.3, How to read and write a file

后端 未结 6 503
夕颜
夕颜 2020-12-07 06:48

I\'d like to know the \"recommended\" way of reading and writing a file in clojure 1.3 .

  1. How to read the whole file
  2. How to read a file line by line
6条回答
  •  心在旅途
    2020-12-07 07:33

    To read a file line by line you no longer need to resort to interop:

    (->> "data.csv"
          io/resource
          io/reader
          line-seq
          (drop 1))
    

    This assumes that your data file is kept in the resources directory and that the first line is header information that can be discarded.

提交回复
热议问题