Java Resource Load getResourceAsStream(String resName, Object obj)

Here you can find the source of getResourceAsStream(String resName, Object obj)

Description

get Resource As Stream

License

Apache License

Declaration

public static InputStream getResourceAsStream(String resName, Object obj) throws FileNotFoundException 

Method Source Code


//package com.java2s;
/*/ Part of JayWormNET source code. (C) 2013 Andrey Bobkov (MEDVEDx64).
Licensed under the Apache License, Version 2.0.  /*/

import java.io.*;

public class Main {
    public static InputStream getResourceAsStream(String resName, Object obj) throws FileNotFoundException {
        InputStream str = obj.getClass().getResourceAsStream(resName.startsWith("/") ? resName : "/" + resName);
        File file = new File(resName);
        if (file.exists())
            return new FileInputStream(file);
        else if (str != null)
            return str;
        else//  ww w.  jav  a 2s.  c o  m
            throw new FileNotFoundException("No such resource: " + resName);
    }
}

Related

  1. getResourceAsStream(String path, Class caller)
  2. getResourceAsStream(String path, ClassLoader cl)
  3. getResourceAsStream(String path, ClassLoader loader)
  4. getResourceAsStream(String relativeName, Class clazz)
  5. getResourceAsStream(String res)
  6. getResourceAsStream(String resource, ClassLoader classLoader)
  7. getResourceAsStream(String resource, ClassLoader classLoader)
  8. getResourceAsStream(String resourcePath)
  9. getResourceAsStreamInClassPath(@SuppressWarnings("rawtypes") Class clazz, String filepath)