On Sat, 20 Dec 2008 03:12:30 -0800 "Darren Austin" <darren.aus...@gmail.com> wrote:
> > Hey folks, > > I am probably missing something obvious here, but is there an good way > to open a resource file that is relative to the current class path? I > want to bundle up some data files with my .clj source in a .jar file. > From the clojure code, I need to open these data files. I looked at > Class.getResourceAsStream(), but I couldn't find a good way to get an > object that would give me a Class object from the package/ns of my > clojure code. Any suggestions on how to achieve this? > > Thanks, > --Darren > > > here's something ... (defn loadTextResource [path] (let [bl (.baseLoader clojure.lang.RT) inps (.getResourceAsStream bl path)] (if inps (with-open [r (BufferedReader. (InputStreamReader. inps))] (let [sb (new StringBuilder)] (loop [c (. r (read))] (if (neg? c) (str sb) (do (. sb (append (char c))) (recur (. r (read)))))))) -- None are more hopelessly enslaved than those who falsely believe they are free — Goethe --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---