Java Resource Load getResourceStreamInPackage(Class clazz, String name)

Here you can find the source of getResourceStreamInPackage(Class clazz, String name)

Description

get Resource Stream In Package

License

Apache License

Declaration

public static InputStream getResourceStreamInPackage(Class<?> clazz, String name) 

Method Source Code

//package com.java2s;
/*/*from  w w w. ja  v  a 2s  .c o m*/
 * Copyright 2014 Amund Elstad.
 *
 * 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 getResourceStreamInPackage(Class<?> clazz, String name) {
        return clazz.getResourceAsStream("/" + clazz.getPackage().getName().replace(".", "/") + "/" + name);
    }
}

Related

  1. getResourceStream(String className, ClassLoader classLoader)
  2. getResourceStream(String name)
  3. getResourceStream(String pathToResource)
  4. getResourceStream(String resource, Class root)
  5. getResourceStreamFromClasspath(Class clazz, String resourceName)
  6. getResourceString(String filename)
  7. getResourceUri(final String packageToScan, final ClassLoader classLoader)
  8. getResourceUrl(final Class aClass, final String aPath)
  9. getResourceUrl(final String resourcePath)