Java Resource Load getResourceReader(final String aResName)

Here you can find the source of getResourceReader(final String aResName)

Description

Loads a resource from the classpath.

License

BSD License

Parameter

Parameter Description
aResName The resource to fetch.

Return

A handle for the resource or null if the resource is not found.

Declaration

public static Reader getResourceReader(final String aResName) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main {
    /**//from  w w w .  jav  a  2  s  .  c  o  m
     * Loads a resource from the classpath.
     * 
     * @param aResName
     *            The resource to fetch.
     * @return A handle for the resource or null if the resource is not found.
     */
    public static Reader getResourceReader(final String aResName) {
        final InputStream resource = getResource(aResName);
        if (resource == null) {
            return null;
        }
        return new InputStreamReader(resource);
    }

    /**
     * Loads a resource from the classpath.
     * 
     * @param aResName
     *            The resource to fetch.
     * @return A handle for the resource or null if the resource is not found.
     */
    public static InputStream getResource(final String aResName) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(aResName);
    }
}

Related

  1. getResourceNames(File dir)
  2. getResourceNames(String resName)
  3. getResourceNamesFromDir(File dir, String extension)
  4. getResourcePath()
  5. getResourcePath(Class c, String name)
  6. getResources(File root, File path, Vector result)
  7. getResources(final Pattern pattern)
  8. getResourceScripts(String path)
  9. getResourcesFromDirectory(File directory)