Java Resource Load getResourceAsStream(String path)

Here you can find the source of getResourceAsStream(String path)

Description

Return the InputStream of the resource provided, following the #findResource(String) rules.

License

Open Source License

Parameter

Parameter Description
path the resource to find.

Exception

Parameter Description
IOException if unable to open the InputStream.

Return

the to the resource, or null if not found.

Declaration

public static InputStream getResourceAsStream(String path) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * 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
 *******************************************************************************/

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**//  w w w .  j  a  va2  s. co  m
     * Return the InputStream of the resource provided, following the {@link #findResource(String)} rules.
     * 
     * @param path
     *            the resource to find.
     * @return the {@link InputStream} to the resource, or null if not found.
     * @throws IOException
     *             if unable to open the {@link InputStream}.
     * @see {@link URL#openStream()}
     */
    public static InputStream getResourceAsStream(String path) throws IOException {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        return cl.getResourceAsStream(path);
    }
}

Related

  1. getResourceAsStream(String name)
  2. getResourceAsStream(String name, Class aClass)
  3. getResourceAsStream(String name, Class clazz)
  4. getResourceAsStream(String name, Class clazz)
  5. getResourceAsStream(String name, Class clzz)
  6. getResourceAsStream(String path, Class caller)
  7. getResourceAsStream(String path, ClassLoader cl)
  8. getResourceAsStream(String path, ClassLoader loader)
  9. getResourceAsStream(String relativeName, Class clazz)