Java Utililty Methods Resource Load

List of utility methods to do Resource Load

Description

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

Method

InputStreamgetResourceAsStream(String filename)
Get a resource as a stream.
File f = new File(filename);
try {
    if (f.exists()) {
        return new FileInputStream(f);
    } else {
        String fname = "classes" + File.separator + filename;
        f = new File(fname);
        if (f.exists()) {
...
InputStreamgetResourceAsStream(String filename)
get Resource As Stream
Thread currentThread = Thread.currentThread();
ClassLoader contextClassLoader = currentThread.getContextClassLoader();
return contextClassLoader.getResourceAsStream(filename);
InputStreamgetResourceAsStream(String filePath)
get Resource As Stream
Thread.currentThread().getContextClassLoader();
InputStream inputstream = ClassLoader.getSystemResourceAsStream(filePath);
if (inputstream == null) {
    inputstream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
if (inputstream == null) {
    inputstream = new FileInputStream(new File(filePath));
return inputstream;
InputStreamgetResourceAsStream(String name)
get Resource As Stream
if (!name.startsWith("bio/gcat/"))
    name = "bio/gcat" + (name.startsWith("/") ? EMPTY : "/") + name;
return localClassLoader.getResourceAsStream(name);
InputStreamgetResourceAsStream(String name)
get Resource As Stream
ClassLoader cl = getClassLoader();
if (cl == null) {
    return null;
return cl.getResourceAsStream(name);
InputStreamgetResourceAsStream(String name)
Returns an input stream from a file, given its name.
return getContextClassLoader().getResourceAsStream(name);
InputStreamgetResourceAsStream(String name)
Load resource as stream if it is present somewhere in the classpath.
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
if (in == null) {
    throw new IOException("could not find " + name + " in classpath");
return in;
InputStreamgetResourceAsStream(String name, Class aClass)
Return the input stream for the given name and class.
if (isBlank(name)) {
    throw new IllegalArgumentException("Parameter name cannot be blank");
;
if (aClass == null) {
    throw new IllegalArgumentException("Parameter aClass is null");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
...
InputStreamgetResourceAsStream(String name, Class clazz)
get Resource As Stream
ClassLoader loader;
InputStream retval = null;
try {
    loader = Thread.currentThread().getContextClassLoader();
    if (loader != null) {
        retval = loader.getResourceAsStream(name);
        if (retval != null)
            return retval;
...
InputStreamgetResourceAsStream(String name, Class clazz)
get Resource As Stream
ClassLoader loader;
if (clazz != null) {
    try {
        loader = clazz.getClassLoader();
        if (loader != null) {
            return loader.getResourceAsStream(name);
    } catch (VirtualMachineError err) { 
...