Skip to content

Instantly share code, notes, and snippets.

@lsgrep
Created December 22, 2014 13:56
Show Gist options
  • Save lsgrep/bfa5c9a09a3d300d4db5 to your computer and use it in GitHub Desktop.
Save lsgrep/bfa5c9a09a3d300d4db5 to your computer and use it in GitHub Desktop.
Clojure Download a file
(defn download-file [url dir]
(let [my-file (last (.split url "/"))]
(if-not (.exists (io/as-file (str dir my-file)))
(try
(with-open [ in (io/input-stream url)
out (io/output-stream (str dir my-file))]
(io/copy in out)
(println my-file " has been downloaded.")
)
(catch Exception e (str "caught exception:" (.getMessage e))))
(print my-file "is already there"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment