Java Resource Path Get getResource(Class cl, String path)

Here you can find the source of getResource(Class cl, String path)

Description

get Resource

License

LGPL

Declaration

public static URL getResource(Class<?> cl, String path) throws IOException 

Method Source Code

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

import java.io.IOException;

import java.net.URL;

public class Main {
    public static URL getResource(Class<?> cl, String path) throws IOException {
        String clp = cl.getName().replace('.', '/') + ".class";
        URL clu = cl.getClassLoader().getResource(clp);
        String s = clu.toString();
        if (s.endsWith(clp))
            return new URL(s.substring(0, s.length() - clp.length()) + path);

        if (s.startsWith("jar:")) {
            String[] ss = s.split("!");
            return new URL(ss[1] + "!/" + path);
        }//from w ww . jav a  2 s .  c om
        return null;
    }
}

Related

  1. getFileResourcePaths(final Class clazz, final String fileNameRegex)
  2. getPath(final Object resource)
  3. getPathOfResource(Class clazz, String fileName)
  4. getPluginResource(Bundle bundle, String resourcePath)
  5. getRelativeResource(Class clazz, String relativePath)
  6. getResource(final Class baseClass, final String path)
  7. getResource(final String path)
  8. getResource(String path)
  9. getResource(String path)