Here you can find the source of getResourceAsStream(String name)
Parameter | Description |
---|---|
name | Name of the resource |
Parameter | Description |
---|---|
IOException | if resource can't be found |
null
if the resource couldn't be found
public static InputStream getResourceAsStream(String name) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.IOException; import java.io.InputStream; public class Main { /**/*ww w. j a va 2s . co m*/ * Load resource as stream if it is present somewhere in the classpath. * @param name Name of the resource * @return instance of an input stream or <code>null</code> if the resource couldn't be found * @throws IOException if resource can't be found */ public static InputStream getResourceAsStream(String name) throws IOException { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(name); if (in == null) { throw new IOException("could not find " + name + " in classpath"); } return in; } /** * Load a resource as stream from a given <code>folder</code>. * * @see #getResourceAsStream(String) */ public static InputStream getResourceAsStream(String folder, String name) throws IOException { return getResourceAsStream(folder + File.separator + name); } }