Here you can find the source of getResourceURL(String resourcePath)
Parameter | Description |
---|---|
resourcePath | Path to the resource. |
Parameter | Description |
---|---|
IOException | when the resource is not found. |
public static URL getResourceURL(String resourcePath) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.URL; public class Main { /**//from w ww. j av a 2 s.c o m * Get an URL of a classpath-relative resource. For a resource placed * in * <pre>src/graphics/xxx/yyy.png</pre> * this would be * <pre>xxx/yyy.png</pre> * * @param resourcePath Path to the resource. * @return URL of resource * @throws IOException when the resource is not found. */ public static URL getResourceURL(String resourcePath) throws IOException { final ClassLoader cl = Thread.currentThread().getContextClassLoader(); final URL url = cl.getResource(resourcePath); if (url == null) throw new IOException("Resource not found: " + resourcePath); return url; } }