Java tutorial
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static InputStream getResourceAsStream(String name, Class clazz) { ClassLoader loader; InputStream retval = null; // https://issues.jboss.org/browse/JGRP-1762: load the classloader from the defining class first if (clazz != null) { try { loader = clazz.getClassLoader(); if (loader != null) { retval = loader.getResourceAsStream(name); if (retval != null) return retval; } } catch (Throwable t) { } } try { loader = Thread.currentThread().getContextClassLoader(); 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; } }