Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@trptcolin
Created November 28, 2011 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trptcolin/1398972 to your computer and use it in GitHub Desktop.
Save trptcolin/1398972 to your computer and use it in GitHub Desktop.
Spaces ruin resource-reading via clojure.java.io??
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment