Java Resource Load getResourceAsStream(String name, Class clazz)

Here you can find the source of getResourceAsStream(String name, Class clazz)

Description

get Resource As Stream

License

LGPL

Declaration

public static InputStream getResourceAsStream(String name, Class clazz) 

Method Source Code

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

import java.io.*;

public class Main {
    public static InputStream getResourceAsStream(String name, Class clazz) {
        ClassLoader loader;//from  w ww  .ja  va2 s.c  om
        InputStream retval = null;

        try {
            loader = Thread.currentThread().getContextClassLoader();
            if (loader != null) {
                retval = loader.getResourceAsStream(name);
                if (retval != null)
                    return retval;
            }
        } catch (Throwable t) {
        }

        if (clazz != null) {
            try {
                loader = clazz.getClassLoader();
                if (loader != null) {
                    retval = loader.getResourceAsStream(name);
                    if (retval != null)
                        return retval;
                }
            } catch (Throwable t) {
            }
        }

        try {
            loader = ClassLoader.getSystemClassLoader();
            if (loader != null) {
                return loader.getResourceAsStream(name);
            }
        } catch (Throwable t) {
        }

        return retval;
    }
}

Related

  1. getResourceAsStream(String name)
  2. getResourceAsStream(String name)
  3. getResourceAsStream(String name)
  4. getResourceAsStream(String name, Class aClass)
  5. getResourceAsStream(String name, Class clazz)
  6. getResourceAsStream(String name, Class clzz)
  7. getResourceAsStream(String path)
  8. getResourceAsStream(String path, Class caller)
  9. getResourceAsStream(String path, ClassLoader cl)