public class PropertiesHelper extends Object
使用1:
public class ConnectionUtils {
static Properties properties = new Properties();
// ... do load properties
// delegate to properties
static PropertiesHelper props = new PropertiesHelper(properties);
public static Connection getConnection() {
// use getRequiredProperty()
DriverManager.getConnection(props.getRequiredString("jdbc.url"));
}
}
指定是否搜索系统属性:
new PropertiesHelper(properties,PropertiesHelper.SYSTEM_PROPERTIES_MODE_OVERRIDE)
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
SYSTEM_PROPERTIES_MODE_FALLBACK
Check system properties if not resolvable in the specified properties.
|
static int |
SYSTEM_PROPERTIES_MODE_NEVER
Never check system properties.
|
static int |
SYSTEM_PROPERTIES_MODE_OVERRIDE
Check system properties first, before trying the specified properties.
|
| 构造器和说明 |
|---|
PropertiesHelper(Properties p) |
PropertiesHelper(Properties p,
int systemPropertiesMode) |
public static final int SYSTEM_PROPERTIES_MODE_NEVER
public static final int SYSTEM_PROPERTIES_MODE_FALLBACK
public static final int SYSTEM_PROPERTIES_MODE_OVERRIDE
public PropertiesHelper(Properties p)
public PropertiesHelper(Properties p, int systemPropertiesMode)
public Properties getProperties()
public void setProperties(Properties props)
public String getAndTryFromSystem(String key)
public int getInt(String key, int defaultValue)
public int getRequiredInt(String key)
public long getLong(String key, long defaultValue)
public boolean getBoolean(String key, boolean defaultValue)
public boolean getRequiredBoolean(String key)
public float getFloat(String key, float defaultValue)
public double getDouble(String key, double defaultValue)
public Object setProperty(String key, int value)
public int[] getIntArray(String key)
public Properties getStartsWithProperties(String prefix)
public void clear()
public Enumeration<?> propertyNames()
public boolean contains(Object value)
public boolean containsKey(Object key)
public boolean containsValue(Object value)
public Enumeration<Object> elements()
public boolean isEmpty()
public Enumeration<Object> keys()
public void list(PrintStream out)
public void list(PrintWriter out)
public void load(InputStream inStream) throws IOException
IOExceptionpublic void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException
public void save(OutputStream out, String comments)
public int size()
public void store(OutputStream out, String comments) throws IOException
IOExceptionpublic void storeToXML(OutputStream os, String comment, String encoding) throws IOException
IOExceptionpublic void storeToXML(OutputStream os, String comment) throws IOException
IOExceptionpublic Collection<Object> values()
Copyright © 2018. All rights reserved.