Here you can find the source of toInputStream(String name, ClassLoader cl)
public static InputStream toInputStream(String name, ClassLoader cl) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URL; public class Main { public static InputStream toInputStream(String name) throws Exception { return toInputStream(name, Thread.currentThread().getContextClassLoader()); }/* w ww.jav a 2s . c o m*/ public static InputStream toInputStream(String name, ClassLoader cl) throws Exception { File file = new File(name); if (file.exists()) { return new FileInputStream(file); } else { URL url = cl.getResource(name); return url.openStream(); } } }