Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BadUncleX/c880a9cc26fd356577681c19595d0982 to your computer and use it in GitHub Desktop.
Save BadUncleX/c880a9cc26fd356577681c19595d0982 to your computer and use it in GitHub Desktop.
文件按行切割
(ns alexcoding.sandbox.splitfile)
(require '[clojure.string :as str])
(def filenumberflag (atom 0))
(with-open [rdr (clojure.java.io/reader "/tmp/yuliaoku.txt")]
(doseq [chunk (partition 1500 (line-seq rdr)) ]
(with-open [w (clojure.java.io/writer (str "/tmp/yuliaoku_" (format "%03d" @filenumberflag) ".txt") :append true)]
(doseq [line chunk]
(.write w line)
(.newLine w)))
(swap! filenumberflag inc)
(println @filenumberflag)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment