Here you can find the source of getInputStream(String resourceOrFile, Class> cls)
public static InputStream getInputStream(String resourceOrFile, Class<?> cls) throws FileNotFoundException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; public class Main { public static InputStream getInputStream(String resourceOrFile) throws FileNotFoundException { return getInputStream(resourceOrFile, Thread.class); }/*from w ww .ja va 2 s . c om*/ public static InputStream getInputStream(String resourceOrFile, Class<?> cls) throws FileNotFoundException { try { return getURL(resourceOrFile, cls).openStream(); } catch (Exception e) { throw new FileNotFoundException(resourceOrFile); } } public static URL getURL(String resourceOrFile, Class<?> cls) throws FileNotFoundException { File file = new File(resourceOrFile); // System.out.println("checking file "); // is file if (file.exists()) { // System.out.println("file exists"); try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new FileNotFoundException(resourceOrFile); } } // is resource if (!file.exists()) { // System.out.println("file resource"); URL url = cls.getResource(resourceOrFile); if (url != null) { return url; } url = cls.getResource("/" + resourceOrFile); if (url != null) { return url; } } throw new FileNotFoundException(resourceOrFile); } }