Java Properties Get getProperty(Properties props, String propname)

Here you can find the source of getProperty(Properties props, String propname)

Description

Check first for a particular property in the System Properties, so that the -Dprop="value" command line arg mechanism can be used to override values defined in the passed in property file.

License

Open Source License

Parameter

Parameter Description
props - property set in which to look.
propname - name of the property to lookup.

Declaration

public static String getProperty(Properties props, String propname) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**/*from  w ww. j a  v  a 2 s. c  om*/
     * Check first for a particular property in the System Properties, so that the -Dprop="value" command line arg
     * mechanism can be used to override values defined in the passed in property file.  This is especially useful
     * for defining the marc.source property to define which file to operate on, in a shell script loop.
     *
     * @param props    - property set in which to look.
     * @param propname - name of the property to lookup.
     * @returns String - value stored for that property (or null if it doesn't exist)
     */
    public static String getProperty(Properties props, String propname) {
        return getProperty(props, propname, null);
    }

    /**
     * Check first for a particular property in the System Properties, so that the -Dprop="value" command line arg
     * mechanism can be used to override values defined in the passed in property file.  This is especially useful
     * for defining the marc.source property to define which file to operate on, in a shell script loop.
     *
     * @param props    - property set in which to look.
     * @param propname - name of the property to lookup.
     * @param defVal   - the default value to use if property is not defined
     * @returns String - value stored for that property (or the  if it doesn't exist)
     */
    public static String getProperty(Properties props, String propname, String defVal) {
        String prop;
        if ((prop = System.getProperty(propname)) != null) {
            return (prop);
        }
        if (props != null && (prop = props.getProperty(propname)) != null) {
            return (prop);
        }
        return defVal;
    }
}

Related

  1. getPropertiesWithPrefix(Properties pro, String prefix)
  2. getProperty(Properties properties, String context, String key, String def)
  3. getProperty(Properties props, String keyword)
  4. getProperty(Properties props, String prefix, String key)
  5. getProperty(Properties props, String propertyName)
  6. getProperty(String[] system_props, Properties props, String prop_name, boolean ignore_sysprops, String default_value)
  7. getPropertyDouble(Properties p, String key)
  8. getPropertyLong(Properties properties, String context, String key, Long def)
  9. getPropertyString(Properties properties, String propertyName)