Java Resource Path Get getResourcePath(Object object, String resource)

Here you can find the source of getResourcePath(Object object, String resource)

Description

Return the fully qualified path of the requested resource object.

License

Open Source License

Parameter

Parameter Description
object the requested object type
the desired resource

Return

its fully qualified path name.

Declaration

public static String getResourcePath(Object object, String resource) 

Method Source Code

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

import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**// www  .ja va 2  s. c o m
     * Return the fully qualified path of the requested resource object.
     * @param object the requested object type
     * @param the desired resource
     * @return its fully qualified path name.
     */
    public static String getResourcePath(Object object, String resource) {

        URL resourceURL = object.getClass().getClassLoader().getResource(resource);

        if (resourceURL != null) {
            try {
                return resourceURL.toURI().getPath();

            } catch (URISyntaxException e) {
                return null;
            }

        } else {
            return null;
        }
    }
}

Related

  1. getResourceListing(Class clazz, String path)
  2. getResourceListing(Class clazz, String path, String glob)
  3. getResourcePath()
  4. getResourcePath(Class clazz, String fileName)
  5. getResourcePath(final Class bundleClazz, final String pathToFile)
  6. getResourcePath(String filename)
  7. getResourcePath(String fileName)
  8. getResourcePath(String name)
  9. getResourcePath(String path)