1<!DOCTYPE html> 2<html><head><meta content="width=device-width, maximum-scale=1.0" name="viewport"><meta content="yes" name="apple-mobile-web-app-capable"><meta content="default" name="apple-mobile-web-app-status-bar-style"><meta content="ClojureDocs" name="apple-mobile-web-app-title"><meta content="XjzqkjEPtcgtLjhnqAvtnVSeveEccs-O_unFGGlbk4g" name="google-site-verification"><meta content="Returns the URL for a named resource. Use the context class loader 3 if no loader is specified." name="description"><meta content="summary" name="twitter:card"><meta content="resource - clojure.java.io" name="twitter:title"><meta content="Returns the URL for a named resource. Use the context class loader 4 if no loader is specified." name="twitter:description"><meta content="resource - clojure.java.io" property="og:title"><meta content="Returns the URL for a named resource. Use the context class loader 5 if no loader is specified." property="og:description"><meta content="https://clojuredocs.org/clojure.java.io/resource" property="og:url"><meta content="website" property="og:type"><meta content="ClojureDocs" property="og:site_name">
5<script type="application/ld+json">{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"clojure.java.io/resource","description":"Returns the URL for a named resource. Use the context class loader\n if no loader is specified.","url":"https://clojuredocs.org/clojure.java.io/resource","programmingLanguage":"Clojure","codeRepository":"https://github.com/clojure/clojure"}</script>
5<link href="https://clojuredocs.org/clojure.java.io/resource" rel="canonical"><title>resource - clojure.java.io | ClojureDocs - Community-Powered Clojure Documentation and Examples</title><link href="/opensearch.xml" rel="search" title="ClojureDocs" type="application/opensearchdescription+xml"><link href="/css/font-awesome.min.css?bbfef9385083d307ad2692c0cf99f611" rel="stylesheet"><link href="/css/bootstrap.min.css?385b964b68acb68d23cb43a5218fade9" rel="stylesheet"><link href="/css/app.css?53cd4ff9fa53f53353ecaccc5bf25365" rel="stylesheet">
5<script>// <![CDATA[ 6window.PAGE_DATA="[\"^ \",\"~:examples\",[[\"^ \",\"~:var\",[\"^ \",\"~:library-url\",\"https://github.com/clojure/clojure\",\"~:name\",\"resource\",\"~:ns\",\"clojure.java.io\"],\"~:author\",[\"^ \",\"~:login\",\"cloojure\",\"~:account-source\",\"clojuredocs\",\"~:avatar-url\",\"https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon\"],\"~:editors\",[[\"^ \",\"^6\",\"cloojure\",\"^7\",\"clojuredocs\",\"^8\",\"https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon\"],[\"^ \",\"^8\",\"https://avatars.githubusercontent.com/u/11081351?v=3\",\"^7\",\"github\",\"^6\",\"rauhs\"],[\"^ \",\"^6\",\"flyboarder\",\"^7\",\"github\",\"^8\",\"https://avatars3.githubusercontent.com/u/147004?v=3\"]],\"~:body\",\"; Use clojure.java.io/resource to read resources from the classpath:\\n\\n(ns rescue.core\\n (:require [clojure.java.io :as io] ))\\n\\n; Populate the file on the command line: \\n; echo \\\"Hello Resources!\\\" > resources/hello.txt\\n(def data-file (io/resource \\n \\\"hello.txt\\\" ))\\n(defn -main []\\n (println (slurp data-file)) )\\n; When do \\\"lein run\\\"\\n; => Hello Resources!\",\"~:created-at\",1399010149000,\"~:updated-at\",1494456807781,\"~:_id\",\"542692d6c026201cdc3270dc\",\"~:user\",null],[\"^ \",\"^1\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^:\",\"(require '(clojure.java.io :as io))\\n\\n;; If the resource does not exist on the classpath a nil is returned.\\n(io/resource \\\"I_do_not_exist.txt\\\")\\n;;=> nil\",\"^5\",[\"^ \",\"^6\",\"phreed\",\"^7\",\"github\",\"^8\",\"https://avatars.githubusercontent.com/u/211644?v=3\"],\"^;\",1435094542239,\"^<\",1435094573241,\"^9\",[[\"^ \",\"^6\",\"phreed\",\"^7\",\"github\",\"^8\",\"https://avatars.githubusercontent.com/u/211644?v=3\"]],\"^=\",\"5589ce0ee4b0fad27b85f91e\",\"^>\",null],[\"^ \",\"^<\",1781761775484,\"^;\",1781761775484,\"^5\",[\"^ \",\"^6\",\"charlot-shaw\",\"^7\",\"github\",\"^8\",\"https://avatars.githubusercontent.com/u/141575226?v=4\"],\"^:\",\"(require '(clojure.java.io :as io))\\n\\n;; If the resource named did not exist when the JVM was started, `nil` will be returned.\\n\\n;; Start your REPL, then create a file.\\n\\n(io/resource \\\"new_file.txt\\\")\\n;;=> nil\\n\\n;; Relaunch the REPL, rerun the above and now the file will be found.\",\"^1\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^=\",\"6a3386ef6a3dcc6730160f75\",\"^>\",null]],\"^1\",[\"^ \",\"~:added\",\"1.2\",\"^4\",\"clojure.java.io\",\"^3\",\"resource\",\"~:file\",\"clojure/java/io.clj\",\"~:type\",\"function\",\"~:column\",1,\"~:line\",449,\"~:tag\",\"java.net.URL\",\"~:arglists\",[\"~#list\",[\"n\",\"n loader\"]],\"~:doc\",\"Returns the URL for a named resource. Use the context class loader\\n if no loader is specified.\",\"^2\",\"https://github.com/clojure/clojure\",\"~:href\",\"/clojure.java.io/resource\"],\"~:notes\",[[\"^ \",\"^:\",\"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`.\",\"^1\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^;\",1435260445537,\"^<\",1435260445537,\"^5\",[\"^ \",\"^6\",\"kyptin\",\"^7\",\"github\",\"^8\",\"https://avatars.githubusercontent.com/u/254619?v=3\"],\"^=\",\"558c561de4b0fad27b85f927\",\"~:can-delete?\",false,\"~:can-edit?\",false],[\"^ \",\"^5\",[\"^ \",\"^6\",\"benwhorwood\",\"^7\",\"github\",\"^8\",\"https://avatars.githubusercontent.com/u/17282487?v=3\"],\"^<\",1469616475473,\"^;\",1469616313988,\"^:\",\"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:\\n\\n<pre>\\n(with-open [in (io/input-stream (io/resource \\\"file.dat\\\"))] ;; resources/file.dat\\n (io/copy in (io/file \\\"/path/to/extract/file.dat\\\"))))\\
6n</pre>\",\"^1\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^=\",\"579890b9e4b0bafd3e2a04be\",\"^J\",false,\"^K\",false]],\"~:see-alsos\",[[\"^ \",\"^;\",1529009753028,\"^5\",[\"^ \",\"^6\",\"MicahElliott\",\"^7\",\"github\",\"^8\",\"https://avatars3.githubusercontent.com/u/159047?v=4\"],\"~:to-var\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"slurp\",\"^4\",\"clojure.core\"],\"~:from-var\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^=\",\"5b22d659e4b00ac801ed9e15\",\"^G\",\"Opens a reader on f and reads all its contents, returning a string.\\n See clojure.java.io/reader for a complete list of supported arguments.\",\"^J\",false,\"^>\",null],[\"^ \",\"^;\",1529010567539,\"^5\",[\"^ \",\"^6\",\"MicahElliott\",\"^7\",\"github\",\"^8\",\"https://avatars3.githubusercontent.com/u/159047?v=4\"],\"^M\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"reader\",\"^4\",\"clojure.java.io\"],\"^N\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^=\",\"5b22d987e4b00ac801ed9e17\",\"^G\",\"Attempts to coerce its argument into an open java.io.Reader.\\n Default implementations always return a java.io.BufferedReader.\\n\\n Default implementations are provided for Reader, BufferedReader,\\n InputStream, File, URI, URL, Socket, byte arrays, character arrays,\\n and String.\\n\\n If argument is a String, it tries to resolve it first as a URI, then\\n as a local file name. URIs with a 'file' protocol are converted to\\n local file names.\\n\\n Should be used inside with-open to ensure the Reader is properly\\n closed.\",\"^J\",false,\"^>\",null],[\"^ \",\"^;\",1529010728887,\"^5\",[\"^ \",\"^6\",\"MicahElliott\",\"^7\",\"github\",\"^8\",\"https://avatars3.githubusercontent.com/u/159047?v=4\"],\"^M\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"line-seq\",\"^4\",\"clojure.core\"],\"^N\",[\"^ \",\"^2\",\"https://github.com/clojure/clojure\",\"^3\",\"resource\",\"^4\",\"clojure.java.io\"],\"^=\",\"5b22da28e4b00ac801ed9e18\",\"^G\",\"Returns the lines of text from rdr as a lazy sequence of strings.\\n rdr must implement java.io.BufferedReader.\",\"^J\",false,\"^>\",null]],\"^>\",null]"; 7//]]></script>
7</head><body class="var-page"><div class="mobile-nav-menu"><section><h4><i class="fa fa-rocket"></i>ClojureDocs</h4><ul class="navbar-nav mobile-navbar-nav nav"><li><a href="/core-library">Core Library<span class="clojure-version">(1.12.4)</span></a></li><li><a href="/quickref">Quick Reference</a></li><li><a href="https://github.com/login/oauth/authorize?client_id=d0242c22610efb54ebbe&redirect_uri=https%3A%2F%2Fclojuredocs.org%2Fgh-callback%2Fclojure.java.io%2Fresource&scope="><i class="fa fa-github-square"></i>Log In</a></li></ul></section><section><h4>Nav</h4><ul class="navbar-nav mobile-navbar-nav nav"><li><a data-animate-buffer="70" data-animate-scroll="true" href="#">Top</a></li><li><a data-animate-buffer="70" data-animate-scroll="true" href="#examples">Examples <span class="examples-count"><span class="badge">3</span></span></a></li><li><a data-animate-buffer="70" data-animate-scroll="true" href="#see-also">See Also <span class="badge">3</span></a></li><li><a data-animate-buffer="70" data-animate-scroll="true" href="#notes">Notes <span class="badge">2</span></a></li></ul></section><section><h4>Namespaces</h4><ul class="navbar-nav mobile-navbar-nav nav"><li><a href="/clojure.core">clojure.core</a></li><li><a href="/clojure.core.async">clojure.core.async</a></li><li><a href="/clojure.core.logic">clojure.core.logic</a></li><li><a href="/clojure.core.logic.fd">clojure.core.logic.fd</a></li><li><a href="/clojure.core.logic.pldb">clojure.core.logic.pldb</a></li><li><a href="/clojure.core.protocols">clojure.core.protocols</a></li><li><a href="/clojure.core.reducers">clojure.core.reducers</a></li><li><a href="/clojure.core.server">clojure.core.server</a></li><li><a href="/clojure.data">clojure.data</a></li><li><a href="/clojure.data.csv">clojure.data.csv</a></li><li><a href="/clojure.datafy">clojure.datafy</a></li><li><a href="/clojure.edn">clojure.edn</a></li><li><a href="/clojure.inspector">clojure.inspector</a></li><li><a href="/clojure.instant">clojure.instant</a></li><li><a href="/clojure.java.browse">clojure.java.browse</a></li><li><a href="/clojure.java.io">clojure.java.io</a></li><li><a href="/clojure.java.javadoc">clojure.java.javadoc</a></li><li><a href="/clojure.java.process">clojure.java.process</a></li><li><a href="/clojure.java.shell">clojure.java.shell</a></li><li><a href="/clojure.main">clojure.main</a></li><li><a href="/clojure.math">clojure.math</a></li><li><a href="/clojure.pprint">clojure.pprint</a></li><li><a href="/clojure.reflect">clojure.reflect</a></li><li><a href="/clojure.repl">clojure.repl</a></li><li><a href="/clojure.repl.deps">clojure.repl.deps</a></li><li><a href="/clojure.set">clojure.set</a></li><li><a href="/clojure.spec.alpha">clojure.spec.alpha</a></li><li><a href="/clojure.stacktrace">clojure.stacktrace</a></li><li><a href="/clojure.string">clojure.string</a></li><li><a href="/clojure.template">clojure.template</a></li><li><a href="/clojure.test">clojure.test</a></li><li><a href="/clojure.test.junit">clojure.test.junit</a></li><li><a href="/clojure.test.tap">clojure.test.tap</a></li><li><a href="/clojure.tools.build.api">clojure.tools.build.api</a></li><li><a href="/clojure.tools.deps.interop">clojure.tools.deps.interop</a></li><li><a href="/clojure.walk">clojure.walk</a></li><li><a href="/clojure.xml">clojure.xml</a></li><li><a href="/clojure.zip">clojure.zip</a></li></ul></section></div><div class="mobile-nav-bar"><header class="navbar"><div class="container"><div class="row"><div class="col-md-10 col-md-offset-1"><a class="navbar-brand" href="/"><i class="fa fa-rocket"></i>ClojureDocs</a><button class="btn btn-default navbar-btn pull-right mobile-menu"><i class="fa fa-bars"></i></button><ul class="navbar-nav nav navbar-right desktop-navbar-nav"><li><a href="/core-library">Core Library</a></li><li><a href="/quickref">Quick Ref</a></li><li><a href="https://github.com/login/oauth/authorize?client_id=d0242c22610efb54ebbe&redirect_uri=https%3A%2F%2Fclojuredocs.org%2Fgh-callback%2Fclojure.java.io%2Fresource&scope="><i class="fa fa-github-square"></i>Log In</a></li></ul><div class="nav-search-widget navbar-right navbar-form"><form action="/search" autocomplete="off" class="search" method="get"><input autocomplete="off" class="placeholder form-control" name="q" placeholder="Looking for? (ctrl-s)" type="text"></form></div></div></div><div class="row"><div class="col-md-10 col-md-offset-1"><div class="ac-results-widget"></div></div></div></div></header></div><div class="sticky-wrapper mobile-push-wrapper"><div class="conj-banner">Clojure/Conj 2026 â Charlotte, NC â Sept 30 - Oct 2 <a href="https://2026.clojure-conj.org/?utm_source=clojuredocs&utm_medium=banner&utm_campaign=conj2026" onclick="_paq.push(['trackEvent', 'Banner', 'Click', 'Conj 2026']);" target="_blank">Learn More & Get Tickets â</a></div><div class="desktop-nav-bar"><header class="navbar"><div class="container"><div class="row"><div class="col-md-10 col-md-offset-1"><a class="navbar-brand" href="/"><i class="fa fa-rocket"></i>ClojureDocs</a><button class="btn btn-default navbar-btn pull-right mobile-menu"><i class="fa fa-bars"></i></button><ul class="navbar-nav nav navbar-right desktop-navbar-nav"><li><a href="/core-library">Core Library</a></li><li><a href="/quickref">Quick Ref</a></li><li><a href="https://github.com/login/oauth/authorize?client_id=d0242c22610efb54ebbe&redirect_uri=https%3A%2F%2Fclojuredocs.org%2Fgh-callback%2Fclojure.java.io%2Fresource&scope="><i class="fa fa-github-square"></i>Log In</a></li></ul><div class="nav-search-widget navbar-right navbar-form"><form action="/search" autocomplete="off" class="search" method="get"><input autocomplete="off" class="placeholder form-control" name="q" placeholder="Looking for? (ctrl-s)" type="text"></form></div></div></div><div class="row"><div class="col-md-10 col-md-offset-1"><div class="ac-results-widget"></div></div></div></div></header></div><div class="container"><div class="row"><div class="col-md-10 col-md-offset-1"><div><div class="row"><div class="col-sm-2 sidenav"><div class="desktop-side-nav" data-sticky-offset="10"><div class="var-page-nav"></div><div class="library-nav"><h5>Namespaces</h5><ul class="ns-tree"><li><span>clojure</span><ul><li><span><a href="/clojure.core">core</a></span><ul><li><span><a href="/clojure.core.async">async</a></span></li><li><span><a href="/clojure.core.logic">logic</a></span><ul><li><span><a href="/clojure.core.logic.fd">fd</a></span></li><li><span><a href="/clojure.core.logic.pldb">pldb</a></span></li></ul></li><li><span><a href="/clojure.core.protocols">protocols</a></span></li><li><span><a href="/clojure.core.reducers">reducers</a></span></li><li><span><a href="/clojure.core.server">server</a></span></li></ul></li><li><span><a href="/clojure.data">data</a></span><ul><li><span><a href="/clojure.data.csv">csv</a></span></li></ul></li><li><span><a href="/clojure.datafy">datafy</a></span></li><li><span><a href="/clojure.edn">edn</a></span></li><li><span><a href="/clojure.inspector">inspector</a></span></li><li><span><a href="/clojure.instant">instant</a></span></li><li><span>java</span><ul><li><span><a href="/clojure.java.browse">browse</a></span></li><li><span class="current"><a href="/clojure.java.io">io</a></span></li><li><span><a href="/clojure.java.javadoc">javadoc</a></span></li><li><span><a href="/clojure.java.process">process</a></span></li><li><span><a href="/clojure.java.shell">shell</a></span></li></ul></li><li><span><a href="/clojure.main">main</a></span></li><li><span><a href="/clojure.math">math</a></span></li><li><span><a href="/clojure.pprint">pprint</a></span></li><li><span><a href="/clojure.reflect">reflect</a></span></li><li><span><a href="/clojure.repl">repl</a></span><ul><li><span><a href="/clojure.repl.deps">deps</a></span></li></ul></li><li><span><a href="/clojure.set">set</a></span></li><li><span>spec</span><ul><li><span><a href="/clojure.spec.alpha">alpha</a></span></li></ul></li><li><span><a href="/clojure.stacktrace">stacktrace</a></span></li><li><span><a href="/clojure.string">string</a></span></li><li><span><a href="/clojure.template">template</a></span></li><li><span><a href="/clojure.test">test</a></span><ul><li><span><a href="/clojure.test.junit">junit</a></span></li><li><span>
7<a href="/clojure.test.tap">tap</a></span></li></ul></li><li><span>tools</span><ul><li><span>build</span><ul><li><span><a href="/clojure.tools.build.api">api</a></span></li></ul></li><li><span>deps</span><ul><li><span><a href="/clojure.tools.deps.interop">interop</a></span></li></ul></li></ul></li><li><span><a href="/clojure.walk">walk</a></span></li><li><span><a href="/clojure.xml">xml</a></span></li><li><span><a href="/clojure.zip">zip</a></span></li></ul></li></ul></div></div></div><div class="col-sm-10"><div class="row var-header"><div class="col-sm-8"><h1 class="var-name">resource</h1></div><div class="col-sm-4"><div class="var-meta"><h4><a href="/clojure.java.io">clojure.java.io</a></h4><span>Available since 1.2</span><span class="source-link"> (<a href="https://github.com/clojure/clojure/blob/clojure-1.12.4/src/clj/clojure/java/io.clj#L449">source</a>) </span></div></div><div class="col-sm-12"><section><ul class="arglists"><li class="arglist">(resource n)</li><li class="arglist">(resource n loader)</li></ul></section></div></div><section><div class="docstring"><pre>Returns the URL for a named resource. Use the context class loader 8 if no loader is specified.</pre><div class="copyright">© Rich Hickey. All rights reserved. <a href="http://www.eclipse.org/legal/epl-v10.html">Eclipse Public License 1.0</a></div></div></section><section><div class="examples-widget" id="examples"></div></section><section><div class="see-alsos-widget" id="see-also"></div></section><section><div class="notes-widget" id="notes"></div></section></div></div></div></div></div></div><div class="sticky-push"></div></div><footer><div class="container"><div class="row"><div class="col-sm-12"><div class="divider">- ⦠-</div></div></div></div></footer>
8<script src="/cljs/clojuredocs.js?e2abd279099e59d240404a25ed1bd08c"></script>
8<script>var _paq = window._paq = window._paq || []; 9 /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ 10 _paq.push(['trackPageView']); 11 _paq.push(['enableLinkTracking']); 12 (function() { 13 var u="https://cognitect.matomo.cloud/"; 14 _paq.push(['setTrackerUrl', u+'matomo.php']); 15 _paq.push(['setSiteId', '15']); 16 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; 17 g.async=true; g.src='https://cdn.matomo.cloud/cognitect.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s); 18 })();</script>
18<script>if(("standalone" in window.navigator) && window.navigator.standalone){ 19var noddy, remotes = false; 20 21document.addEventListener('click', function(event) { 22 23noddy = event.target; 24 25while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") { 26noddy = noddy.parentNode; 27} 28 29if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) 30{ 31event.preventDefault(); 32document.location.href = noddy.href; 33} 34 35},false); 36}</script>
36</body></html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.