Here you can find the source of getInputStreamFromClasspathFile(final String fileName)
public static InputStream getInputStreamFromClasspathFile(final String fileName) throws FileNotFoundException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.net.URL; public class Main { public static InputStream getInputStreamFromClasspathFile(final String fileName) throws FileNotFoundException { return new FileInputStream(getFileFromClasspath(fileName)); }//from ww w . j av a 2 s . c om /** * Load the resource either using current class loader or using parent class * loader * * @param fileName * @return */ public static File getFileFromClasspath(final String fileName) { File file = null; // Load the resource using current class loader URL url = Thread.currentThread().getClass().getResource(fileName); if (url != null) { file = new File(url.getFile()); } else { // load the resource using the parent context url = Thread.currentThread().getContextClassLoader().getResource(fileName); if (url != null) { file = new File(url.getFile()); } } return file; } }