How to load program resources in Clojure

前端 未结 4 1509
太阳男子
太阳男子 2021-01-31 09:30

How do you load program resources such as icons, strings, graphical elements, scripts, and so on in a Clojure program? I am using a project layout similar to that in many Java p

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 09:51

    I placed the file in testpkg/test.txt (relative to current directory).

    Code:

    (def x 5)
    (def nm "testpkg/test.txt")
    (def thr (Thread/currentThread))
    (def ldr (.getContextClassLoader thr))
    (def strem (.getResourceAsStream ldr nm))
    (def strem2 (ClassLoader/getSystemResource nm))
    (. System/out (println "First Approach:"))
    (. System/out (println strem))
    (. System/out (println))
    (. System/out (println))
    (. System/out (println "Second Approach:"))
    (. System/out (println strem2))
    

    $ java -cp .\;clojure.jar clojure.main test.clj

    First Approach: java.io.BufferedInputStream@1549f94

    Second Approach: file:/C:/jsight/javadevtools/clojure-1.1.0/testpkg/test.txt

提交回复
热议问题