Here you can find the source of getResource(Class> c, String name)
Parameter | Description |
---|---|
c | The class to return the resource on. |
name | The resource name. |
public static InputStream getResource(Class<?> c, String name)
//package com.java2s; // * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * import java.io.*; public class Main { /**//from w ww. j a v a 2 s. c o m * Similar to {@link Class#getResourceAsStream(String)} except looks up the * parent hierarchy for the existence of the specified resource. * * @param c The class to return the resource on. * @param name The resource name. * @return An input stream on the specified resource, or <jk>null</jk> if the resource could not be found. */ public static InputStream getResource(Class<?> c, String name) { if (name == null) return null; while (c != null) { InputStream is = c.getResourceAsStream(name); if (is != null) return is; c = c.getSuperclass(); } return null; } }