Here you can find the source of loadProperties(final Properties properties, final String fileName, final ClassLoader cl)
Parameter | Description |
---|---|
properties | a parameter |
fileName | a parameter |
cl | a parameter |
public static void loadProperties(final Properties properties, final String fileName, final ClassLoader cl)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Martin Lippert and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * //from w ww. j ava 2s .c o m * Contributors: * Martin Lippert initial implementation * Angelo ZERR manage springweaver into Jpa context *******************************************************************************/ import java.io.IOException; import java.net.URL; import java.util.Enumeration; import java.util.Properties; public class Main { /** * Load properties file fileName and put it properties into properties * instance. * * @param properties * @param fileName * @param cl */ public static void loadProperties(final Properties properties, final String fileName, final ClassLoader cl) { // Loop for fileName properties file Enumeration<URL> urlProperties = null; try { urlProperties = cl == null ? ClassLoader.getSystemResources(fileName) : cl.getResources(fileName); } catch (IOException e) { return; } Properties fileProperties = new Properties(); while (urlProperties.hasMoreElements()) { URL url = urlProperties.nextElement(); try { if (url != null) { // Load properties file fileProperties.load(url.openStream()); // merge properties file lodead into the properties.o properties.putAll(fileProperties); } } catch (Exception e) { e.printStackTrace(); } } } }