1.3.0 permalink Arrow_down_16x16

resource

clojure.java.io

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

1 Example top

  • ; Use clojure.java.io/resource to read resources from the classpath:
    
    (ns rescue.core
      (:require [clojure.java.io :as io] ))
    
    ; Populate the file on the command line:  
    ;   echo "Hello Resources!" > resources/hello.txt
    (def data-file (io/file
                     (io/resource 
                       "hello.txt" )))
    (defn -main []
      (println (slurp data-file)) )
    ; When do "lein run"
    ; => Hello Resources!
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/java/io.clj:423 top

(defn ^URL resource
  "Returns the URL for a named resource. Use the context class loader
   if no loader is specified."
  {:added "1.2"}
  ([n] (resource n (.getContextClassLoader (Thread/currentThread))))
  ([n ^ClassLoader loader] (.getResource loader n)))
Vars in clojure.java.io/resource:
Used in 0 other vars

Comments top

No comments for resource. Log in to add a comment.