clojure.java.io/resource¶
Returns the URL for a named resource. Use the context class loader if no loader is specified.
Examples¶
Note by kyptin¶
If you need to slurp a file from a JAR file, don't call io/file on the result of calling io/resource, or you will get an exception that says the resource is "not a file". Instead, call slurp directly on the result of io/resource.
Note by benwhorwood¶
If you need to copy a binary file from a running JAR (or WAR), don't call slurp as it will try and decode the file. Instead, extract similarily to:
(with-open [in (io/input-stream (io/resource "file.dat"))] ;; resources/file.dat
(io/copy in (io/file "/path/to/extract/file.dat"))))
See also¶
Content from the matching ClojureDocs page, with authors credited on each contribution.