Here you can find the source of loadConfig(String path, ClassLoader classLoader)
Parameter | Description |
---|---|
path | path to the config, which is a class resources or a url or a file |
public static InputStream loadConfig(String path, ClassLoader classLoader)
//package com.java2s; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import static java.lang.Thread.currentThread; public class Main { /**/*from ww w . jav a 2 s . c o m*/ * Opens input stream to the specified path, which can be a class resources resolved using the context class loader, * a url or a file * * @param path path to the config, which is a class resources or a url or a file * @return input stream or null if the path wasn't recognized */ public static InputStream loadConfig(String path) { return loadConfig(path, currentThread().getContextClassLoader()); } /** * Opens input stream to the specified path, which can be a class resources resolved using the provided class * loader, a url or a file * * @param path path to the config, which is a class resources or a url or a file * @return input stream or null if the path wasn't recognized */ public static InputStream loadConfig(String path, ClassLoader classLoader) { InputStream input = null; URL resource = classLoader.getResource(path); if (resource != null) { try { input = resource.openStream(); } catch (IOException exception) { // it's not a class } } if (input == null) { try { input = new URL(path).openStream(); } catch (IOException exception) { // it's not an url } } if (input == null) { try { input = new FileInputStream(path); } catch (IOException exception) { // it's not a file } } return input; } }