Here you can find the source of readFileAsResource(String fileName)
public static InputStream readFileAsResource(String fileName) throws IOException
//package com.java2s; //License from project: Apache License import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; public class Main { public static InputStream readFileAsResource(String fileName) throws IOException { InputStream f;/* w w w. ja v a 2s .com*/ try { FileInputStream fis = new FileInputStream(fileName); f = fis; } catch (FileNotFoundException ex) { // FileNotFound f = new Object() { }.getClass().getEnclosingClass().getClassLoader().getResourceAsStream(fileName); } if (f == null) { throw new IOException("Cannot load file " + fileName); } return f; } }