public
Created

Spaces ruin resource-reading via clojure.java.io??

  • Download Gist
gistfile1.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
(require '[clojure.java.io :as jio])
 
(def f (java.io.File/createTempFile "has spaces" "txt"))
(jio/as-url f)
;=> #<URL file:/tmp/has spaces2596746647349806731txt>
;;; Note the lack of URL-escaping
 
(slurp f)
;=> ""
 
(def loader
(java.net.URLClassLoader. (into-array [(jio/as-url (.getParentFile f))])))
 
(def f-resource
(jio/resource (.getName f) loader))
 
(slurp f-resource)
;=> FileNotFoundException /tmp/has%20spaces8769028438726695263txt (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.