Here you can find the source of getResourceAsStream(final String resourceName, final Class> caller)
public static InputStream getResourceAsStream(final String resourceName, final Class<?> caller)
//package com.java2s; import java.io.InputStream; public class Main { public static InputStream getResourceAsStream(final String resourceName, final Class<?> caller) { final String resource; if (resourceName.startsWith("/")) { resource = resourceName.substring(1); } else {/* www . j a v a 2 s . c o m*/ final Package callerPackage = caller.getPackage(); if (callerPackage != null) { resource = callerPackage.getName().replace('.', '/') + '/' + resourceName; } else { resource = resourceName; } } final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); if (threadClassLoader != null) { final InputStream is = threadClassLoader.getResourceAsStream(resource); if (is != null) { return is; } } final ClassLoader classLoader = caller.getClassLoader(); if (classLoader != null) { final InputStream is = classLoader.getResourceAsStream(resource); if (is != null) { return is; } } return ClassLoader.getSystemResourceAsStream(resource); } }