Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.cantaa.util;
 import java.util.List;
Load properties for different environments.

Hans Lesmeister
public class PropertiesLoader {
    private static final Logger log = LoggerFactory.getLogger(PropertiesLoader.class);
    public static Properties loadProperties(String[] propResourceNames) {
        Properties properties = new Properties();
        for (String propFile : propResourceNames) {
        return properties;
    private static void loadPropertiesFromResources(String propFileProperties targetProperties) {
        InputStream in = PropertiesLoader.class.getResourceAsStream("/" + propFile);
        if (in == null) {
            // Properties-File does not exist. Ignore
            .warn("Properties File {} does not exist."propFile);
        .info("Loading properties from file: {}"propFile);

Loads properties from the stream and adds them to the applied target properties. The input stream is closed after reading the properties so the caller does not need to take care about that.

in Stream to read from. May not be null, the caller must take care that the stream is not null
    public static void loadPropertiesFromStream(InputStream inProperties targetProperties) {
        try {
            Properties properties = new Properties();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {

Write the contents of a properties instance to the log

props Properties to log
    public static void logProperties(Properties props) {
        .info("*** Configured Properties ***");
        List<Stringlist = getPropertiesAsList(props);
        for (String s : list) {
    public static List<StringgetPropertiesAsList(Properties properties) {
        List<Stringlist = new ArrayList<String>(properties.size());
        Enumeration en = properties.propertyNames();
        while (en.hasMoreElements()) {
            String property = (Stringen.nextElement();
            list.add(property + " = " + properties.getProperty(property));
        return list;
New to GrepCode? Check out our FAQ X