Here you can find the source of getResourceAsStream(String resource, ClassLoader classLoader)
Parameter | Description |
---|---|
resource | The resource to find |
classLoader | the class loader |
Parameter | Description |
---|---|
IOException | If the resource cannot be found or read |
public static InputStream getResourceAsStream(String resource, ClassLoader classLoader) throws IOException
//package com.java2s; /**//from w ww . j a va 2 s.com * Copyright 2008-2016 Juho Jeong * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.InputStream; public class Main { /** * Returns a resource on the classpath as a Stream object. * * @param resource The resource to find * @param classLoader the class loader * @return The resource * @throws IOException If the resource cannot be found or read */ public static InputStream getResourceAsStream(String resource, ClassLoader classLoader) throws IOException { InputStream in = null; if (classLoader != null) in = classLoader.getResourceAsStream(resource); if (in == null) in = ClassLoader.getSystemResourceAsStream(resource); if (in == null) throw new IOException("Could not find resource " + resource); return in; } }