Here you can find the source of getResourceStreamFromClasspath(Class> clazz, String resourceName)
Parameter | Description |
---|---|
clazz | a parameter |
resourceName | a parameter |
public static InputStream getResourceStreamFromClasspath(Class<?> clazz, String resourceName)
//package com.java2s; import java.io.InputStream; public class Main { /**//from w ww . ja v a2s . c om * Helper method for grabbing a file from the classpath and returning an InputStream * * @param clazz * @param resourceName * @return */ public static InputStream getResourceStreamFromClasspath(Class<?> clazz, String resourceName) { InputStream is = clazz.getResourceAsStream(resourceName); if (is == null) { is = clazz.getClassLoader().getResourceAsStream(resourceName); if (is == null) throw new RuntimeException("resource not found in classpath: " + resourceName + " class is: " + clazz.getCanonicalName()); } return is; } }