Created
December 22, 2014 13:56
-
-
Save lsgrep/bfa5c9a09a3d300d4db5 to your computer and use it in GitHub Desktop.
Clojure Download a file
This file contains 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
(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