Here you can find the source of getStreamForPath(ClassLoader loader, String path)
static InputStream getStreamForPath(ClassLoader loader, String path) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.*; import java.net.URISyntaxException; import java.net.URL; public class Main { static InputStream getStreamForPath(ClassLoader loader, String path) throws IOException { URL url = loader.getResource(path); if (url == null) { return null; }/*from w w w. j a v a 2s.c om*/ // This *should* handle Tomcat better, where the Tomcat class loader appears to be caching // the contents of files; this bypasses Tomcat to re-read the files from the disk directly. if (url.getProtocol().equals("file")) { try { return new FileInputStream(new File(url.toURI())); } catch (URISyntaxException e) { return null; } } return url.openStream(); } }