Here you can find the source of getResourceAsStream(String path, ClassLoader loader)
protected static InputStream getResourceAsStream(String path, ClassLoader loader)
//package com.java2s; import java.io.*; public class Main { protected static InputStream getResourceAsStream(String path, ClassLoader loader) { // make sure the class loader isn't null if (loader == null) { // log.debug("No loader for get resource request", "path", path); return null; }/*from w w w. j a v a 2s . c o m*/ // try the path as is InputStream in = loader.getResourceAsStream(path); if (in != null) { return in; } // try toggling the leading slash return loader.getResourceAsStream(togglePath(path)); } protected static String togglePath(String path) { if (path.startsWith("/")) { return path.substring(1); } else { return "/" + path; } } }