Here you can find the source of getResource(String name)
Parameter | Description |
---|---|
name | Name of the resource |
Parameter | Description |
---|---|
IOException | if resource can't be found |
null
if the resource couldn't be found
public static URL getResource(String name) throws IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.net.URL; public class Main { /**/*ww w .j a va 2s .c o m*/ * Get URL name of resource and check if it exists somewhere in the classpath. * @param name Name of the resource * @return instance of an input stream or <code>null</code> if the resource couldn't be found * @throws IOException if resource can't be found */ public static URL getResource(String name) throws IOException { URL url = Thread.currentThread().getContextClassLoader().getResource(name); if (url == null) { throw new IOException("could not find " + name + " in classpath"); } return url; } /** * Get URL of a resource from a given <code>folder</code>. * * @see #getResource(String) */ public static URL getResource(String folder, String name) throws IOException { return getResource(folder + "/" + name); } }