Java Class Path getPath(final String aPath, final Class aClass)

Here you can find the source of getPath(final String aPath, final Class aClass)

Description

get Path

License

Open Source License

Declaration

public static String getPath(final String aPath, final Class<?> aClass)
            throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

public class Main {
    public static final String CLASSPATH_PREFIX = "classpath:";

    public static String getPath(final String aPath, final Class<?> aClass)
            throws IOException {
        final URL url = getClasspathUrl(aClass, aPath);
        return url != null ? url.toString() : aPath;
    }//from  ww w.  j  a va 2s  . c  o  m

    public static URL getClasspathUrl(final Class<?> aClass,
            final String aPath) throws IOException {
        if (aPath != null && aPath.startsWith(CLASSPATH_PREFIX)) {
            return getResourceUrl(aClass,
                    aPath.substring(CLASSPATH_PREFIX.length()));
        } else {
            return null;
        }
    }

    public static URL getResourceUrl(final Class<?> aClass,
            final String aPath) throws IOException {
        final URL url = aClass.getResource(aPath);
        if (url == null) {
            throw new FileNotFoundException("Resource not found for "
                    + aClass.toString() + ": " + aPath);
        } else {
            return url;
        }
    }
}

Related

  1. getFile(Class base, String path)
  2. getFullPathOfClass(Class cls)
  3. getFullpathRessources(Class c, String ressource)
  4. getInputStream(Class cls, String path)
  5. getPath(Class tClass)
  6. getPath(String name, Class relativeTo)
  7. getProgramRootPath(Class clazz)
  8. getRootAbsolutePathname(final Class clazz)
  9. getRunClassAllPath(Object obj)