Java Resource Load getResourceAsStream(Class clazz, String fileName)

Here you can find the source of getResourceAsStream(Class clazz, String fileName)

Description

get Resource As Stream

License

Apache License

Declaration

public static InputStream getResourceAsStream(Class<?> clazz, String fileName) 

Method Source Code


//package com.java2s;
/*//from w w w. ja v a 2 s  .  com
 * Copyright 2010 Granule Inc.
 * 
 * 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.InputStream;

public class Main {
    public static InputStream getResourceAsStream(Class<?> clazz, String fileName) {
        InputStream is = clazz.getResourceAsStream(fileName);
        if (is == null) {
            is = clazz.getClassLoader().getResourceAsStream(fileName);
        }
        if (is == null) {
            is = ClassLoader.getSystemResourceAsStream(fileName);
        }
        if (is == null) {
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        }
        return is;
    }
}

Related

  1. getResourceAsStream(Class baseclass, String name)
  2. getResourceAsStream(Class claz, String name)
  3. getResourceAsStream(Class clazz, String name)
  4. getResourceAsStream(Class clazz, String resource)
  5. getResourceAsStream(Class clazz, String resource, boolean checkThreadContextFirst)
  6. getResourceAsStream(Class clazz, String resource)
  7. getResourceAsStream(Class clazz, String resourceName)
  8. getResourceAsStream(Class testClass, String resource)
  9. getResourceAsStream(final String fileName, ClassLoader classLoader)