Java Resource Path Get getResourcePath(String resource)

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

Description

Returns the path of the given resource.

License

Open Source License

Parameter

Parameter Description
resource the resource to find

Return

the path of the resource, null if none found

Declaration

public static String getResourcePath(String resource) 

Method Source Code

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

import java.net.URL;

public class Main {
    /**/*from  w  ww.  j  a v  a 2s .  c  o m*/
     * Returns the path of the given resource.
     * The resource needs to be located inside a source folder and the resource name given relative to that,
     * including packages.
     *
     * @param resource the resource to find
     * @return the path of the resource, null if none found
     */
    public static String getResourcePath(String resource) {
        return getResourceURL(resource).getPath();
    }

    /**
     * Returns the {@link URL} of the given resource.
     * The resource needs to be located inside a source folder and the resource name given relative to that,
     * including packages.
     *
     * @param resource the resource to find
     * @return the URL of the resource, null if none found
     */
    public static URL getResourceURL(String resource) {
        return ClassLoader.getSystemResource(resource);
    }
}

Related

  1. getResourcePath(Object object, String resource)
  2. getResourcePath(String fileName)
  3. getResourcePath(String filename)
  4. getResourcePath(String name)
  5. getResourcePath(String path)
  6. getResourcePath(String resource)
  7. getResources(ClassLoader cl, String resourcePath)
  8. getResources(String path, ClassLoader loader)
  9. getResources(String resourcePath, Class caller)