文件按行切割
Last active
April 11, 2018 05:36
-
-
Save BadUncleX/c880a9cc26fd356577681c19595d0982 to your computer and use it in GitHub Desktop.
文件按行切割
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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