resource

added
1.2

ns
clojure.java.io

type
function

(resource n) (resource n loader)

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

                ; 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/resource 
                   "hello.txt" ))
(defn -main []
  (println (slurp data-file)) )
; When do "lein run"
; => Hello Resources!
            
                (require '(clojure.java.io :as io))

;; If the resource does not exist on the classpath a nil is returned.
(io/resource "I_do_not_exist.txt")
;;=> nil