Java Utililty Methods Resource Path Get

List of utility methods to do Resource Path Get

Description

The list of methods to do Resource Path Get are organized into topic(s).

Method

StringgetResourcePath(Class clazz, String fileName)
get Resource Path
URL resource = clazz.getResource(fileName);
return resource == null ? null : resource.getPath();
StringgetResourcePath(final Class bundleClazz, final String pathToFile)
Returns the absolute path of the resource from the bundle
final Bundle bundle = FrameworkUtil.getBundle(bundleClazz);
final URL url = bundle.getEntry(pathToFile);
return new File(url.getPath()).getAbsolutePath();
StringgetResourcePath(Object object, String resource)
Return the fully qualified path of the requested resource object.
URL resourceURL = object.getClass().getClassLoader().getResource(resource);
if (resourceURL != null) {
    try {
        return resourceURL.toURI().getPath();
    } catch (URISyntaxException e) {
        return null;
} else {
...
StringgetResourcePath(String fileName)
Return the absolute path of the specified file resource on the classpath.
URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
if (url == null) {
    throw new IOException("Failed to locate resource " + fileName);
File file;
try {
    file = new File(url.toURI());
} catch (URISyntaxException urise) {
...
StringgetResourcePath(String filename)
get Resource Path
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
return classloader.getResource(filename).toURI().toString();
StringgetResourcePath(String name)
get Resource Path
URL pathUrl = Thread.currentThread().getContextClassLoader().getResource(name);
if (pathUrl != null) {
    return pathUrl.getPath();
return null;
StringgetResourcePath(String path)
get Resource Path
URL dir_url = ClassLoader.getSystemResource(path);
return dir_url.getFile();
StringgetResourcePath(String resource)
Returns the path of the given resource.
return getResourceURL(resource).getPath();
URLgetResourcePath(String resource)
get Resource Path
return ClassLoader.getSystemResource(resource);
EnumerationgetResources(ClassLoader cl, String resourcePath)
Returns a resources founded from the ClassLoader.
try {
    return cl == null ? ClassLoader.getSystemResources(resourcePath) : cl.getResources(resourcePath);
} catch (IOException e) {
    e.printStackTrace();
return null;