Skip to content

clojure.java.io/resource

View this page on ClojureDocs

Type: function Added: Clojure 1.2 Examples: 3 Runnable: 0
([n] [n loader])

Returns the URL for a named resource. Use the context class loader if no loader is specified.

Examples

by cloojure on . May have evaluation errors.
by phreed on . May have evaluation errors.
by charlot-shaw on . May have evaluation errors.

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.