Java Resource Get getResource(String folder, String name)

Here you can find the source of getResource(String folder, String name)

Description

Get URL of a resource from a given folder.

License

LGPL

Declaration

public static URL getResource(String folder, String name) throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.IOException;

import java.net.URL;

public class Main {
    /**// ww w .j  a va  2s . co 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);
    }
}

Related

  1. getResource(final String res)
  2. getResource(final String resource)
  3. getResource(final String resourceName, final Class caller)
  4. getResource(String filename)
  5. getResource(String filename)
  6. getResource(String inResource)
  7. getResource(String key, String bundleName, Locale locale)
  8. getResource(String name)
  9. getResource(String name)