clojure.java.io/as-url converts a location representation into a Java URL object, avoiding direct java.net.URL construction. String locations may identify classpath resources, local files, or protocols such as http. section 22.8
Equivalent file URLs
A string and a java.io.File can produce equivalent URLs. A java.nio.file.Path must first be converted with toUri unless Coercions is extended: (def u1 (as-url "file:///tmp/words")) (def u2 (as-url (file "/tmp/words"))) (= u1 u2) ;; true section 22.8
(require '[clojure.java.io :refer [as-url file]])
(import 'java.nio.file.FileSystems)
(def path ; #1
(.. FileSystems
getDefault
(getPath "/tmp" (into-array String ["words"]))
toUri))
(def u1 (as-url "file:///tmp/words")) ; #2
(def u2 (as-url (file "/tmp/words"))) ; #3
(def u3 (as-url path)) ; #4
(= u1 u2 u3) ; #5
;; true
Compare URL creation from a string, java.io.File, and a Path-derived URI. section 22.8
