Here you can find the source of getResource(String inResource)
Parameter | Description |
---|---|
inResource | a parameter |
public static InputStream getResource(String inResource)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.InputStream; import java.net.URL; public class Main { /**//from ww w.j a v a 2 s . co m * * trying to fetch data from the following resources * * CLASSPATH, * FILE, * URL * * @param inResource * @return */ public static InputStream getResource(String inResource) { return getResource(inResource, true); } public static InputStream getResource(String inResource, final boolean inAllowUrlResolution) { InputStream theIs = null; try { theIs = inResource == null ? null : getResourceUrl(inResource, inAllowUrlResolution).openStream(); } catch (Exception e) { // swallow } return theIs; } public static URL getResourceUrl(String inResource) { return getResourceUrl(inResource, true); } public static URL getResourceUrl(String inResource, boolean inAllowUrlResolution) { if (inResource == null) { return null; } URL theIs = null; try { String theResource = inResource; theResource = theResource != null && theResource.length() > 0 && theResource.charAt(0) == '/' ? theResource.substring(1) : theResource; theIs = Thread.currentThread().getContextClassLoader().getResource(theResource); } catch (Exception e) { // swallow } try { theIs = theIs != null ? theIs : new File(inResource).toURI().toURL(); } catch (Exception e) { // swallow } try { theIs = theIs != null || inAllowUrlResolution == false ? theIs : new URL(inResource); } catch (Exception e) { // swallow } return theIs; } }