Java Resource Get getResource(Class _class, String resource)

Here you can find the source of getResource(Class _class, String resource)

Description

Find the requested resource (file) like Class.getResource(), but it works for both applets and applications.

License

Open Source License

Declaration

static public URL getResource(Class _class, String resource) 

Method Source Code

//package com.java2s;

import java.net.URL;

public class Main {
    /** Find the requested resource (file) like Class.getResource(), but it works
     * for both applets and applications. Returns null if it cannot find the resource.
     *///from   w  ww  .j  a  v  a 2  s .co m
    static public URL getResource(Class _class, String resource) {
        URL url = _class.getResource(resource);
        if (url == null) {
            /*
             try {
             url = new URL(applet.getCodeBase() + resource);
             }
             catch (java.net.MalformedURLException e) {
             e.printStackTrace();
             }
             */
        }

        return url;
    }
}

Related

  1. getResource(Class baseclass, String name)
  2. getResource(Class c, String name)
  3. getResource(Class clazz, String resource)
  4. getResource(Class controllerClass)