Java Utililty Methods Resource Get

List of utility methods to do Resource Get

Description

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

Method

byte[]getResourceAsBytes(String resource)
Gets the resource as bytes.
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource(resource);
InputStream is = url.openStream();
return getStreamContentAsBytes(is);
FilegetResourceAsFile(Class clazz, String resource)
Gets a resource relative to the given class.
return new File(clazz.getResource(resource).getFile());
FilegetResourceAsFile(Class klass, String resource)
Retrieves the file corresponding to the class resource
URL url = klass.getResource(resource);
return new File(url.getFile());
FilegetResourceAsFile(Class sourceClass, String reference)
get Resource As File
return new File(sourceClass.getResource(reference).toURI());
FilegetResourceAsFile(Class clazz, String fn)
Get a file to read the raw contents of the given resource :)
URL url = clazz.getResource(fn);
if (url == null || url.getFile() == null) {
    throw new IOException("resource \"" + fn + "\" relative to " + clazz + " not found.");
return new File(url.getFile());
FilegetResourceAsFile(Class clazz, String name)
Returns a File for the specified resource, associated with the specified class.
URL url = clazz.getResource(name);
if (url == null) {
    throw new FileNotFoundException(name + " (resource not found)");
return new File(url.getFile());
FilegetResourceAsFile(Class clazz, String rscName)
get Resource As File
File file = null;
try {
    final URL url = clazz.getClassLoader().getResource(rscName);
    if (url != null)
        file = new File(new URI(url.toString()));
} catch (URISyntaxException e) {
    e.printStackTrace();
return file;
FilegetResourceAsFile(final Class clazz, final String name)
get Resource As File
String absolutePath = getAbsolutePath(clazz, name);
try {
    URL url = clazz.getResource(absolutePath);
    if (url != null) {
        return new File(url.toURI());
    } else {
        return null;
} catch (URISyntaxException ex) {
    return null;
FilegetResourceAsFile(final String filename, final Class theClass)
get Resource As File
try {
    final java.net.URL resURL = theClass.getClassLoader().getResource(filename);
    if (resURL != null) {
        return new File(resURL.getFile());
} catch (Exception e) {
    throw new IOException("Unable to open " + filename);
throw new IOException("resURL==null Unable to open " + filename);
FilegetResourceAsFile(String name)
Returns a File pointing to a resource, given its name.
String resource = getResourceAsString(name);
if (resource.startsWith("vfs:/"))
    ;
resource.replace("vfs:/", "file:/");
return (resource == null) ? null : new File(resource);