Java Properties Load loadProperties(Properties properties, Class baseClass, String... propertiesName)

Here you can find the source of loadProperties(Properties properties, Class baseClass, String... propertiesName)

Description

load Properties

License

Open Source License

Declaration

@SuppressWarnings("unused")
    public static Properties loadProperties(Properties properties, Class<?> baseClass, String... propertiesName) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Main {
    @SuppressWarnings("unused")
    public static Properties loadProperties(Properties properties, Class<?> baseClass, String... propertiesName) {
        if (properties == null) {
            properties = new Properties();
        }/*from  www.j  a va 2s.  c  o  m*/
        for (String propertyName : propertiesName) {
            properties = loadProperties(properties, baseClass, propertyName);
        }
        return properties;
    }

    @SuppressWarnings("unused")
    public static Properties loadProperties(Properties properties, String... paths) {
        if (properties == null) {
            properties = new Properties();
        }
        for (String path : paths) {
            properties = loadProperties(properties, path);
        }
        return properties;
    }

    public static Properties loadProperties(Properties properties, Class<?> clazz, String bundle) {
        if (properties == null) {
            properties = new Properties();
        }
        InputStream in = null;
        try {
            in = clazz.getResourceAsStream(bundle);
            properties.load(in);

        } catch (IOException e) {
            System.err.println("Could not load properties for bundle " + bundle);
            e.printStackTrace();

        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignored) {
                }
            }
        }

        return properties;
    }

    public static Properties loadProperties(Properties properties, String path) {
        if (properties == null) {
            properties = new Properties();
        }
        InputStream in = null;
        try {
            in = new FileInputStream(path);
            properties.load(in);

        } catch (IOException e) {
            System.err.println("Could not load properties for file " + path);
            e.printStackTrace();

        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignored) {
                }
            }
        }

        return properties;
    }
}

Related

  1. loadProperties(Class clazz, String name)
  2. loadProperties(Class clazz)
  3. loadProperties(Class clazz, String name)
  4. loadProperties(Properties p, String progname)
  5. loadProperties(Properties properties, Class clazz, String propDir, String name)
  6. loadProperties(Properties props, final Class clazz, final String resourceName)
  7. loadProperties(String bucketName, String key)
  8. loadProperties(String conf)
  9. loadProperties(String name, ClassLoader loader)