Here you can find the source of getResourceStream(Class> clazz, String resourceName)
Parameter | Description |
---|---|
resourceName | a parameter |
path | a parameter |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
public static InputStream getResourceStream(Class<?> clazz, String resourceName) throws FileNotFoundException
//package com.java2s; /*// ww w .j av a 2 s . c om * Copyright (c) Mirth Corporation. All rights reserved. * * http://www.mirthcorp.com * * The software in this package is published under the terms of the MPL license a copy of which has * been included with this distribution in the LICENSE.txt file. */ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; public class Main { /** * Returns a resource as a stream by checking: * * 1. The classpath for a resource with the specified name * 2. For a file with the specified path * * @param resourceName * @param path * @return * @throws FileNotFoundException */ public static InputStream getResourceStream(Class<?> clazz, String resourceName) throws FileNotFoundException { String cpResourceName = null; if (!resourceName.startsWith("/")) { cpResourceName = "/" + resourceName; } else { cpResourceName = resourceName; } InputStream is = clazz.getResourceAsStream(cpResourceName); if (is == null) { is = new FileInputStream(resourceName); } return is; } }