You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.9 KiB
85 lines
1.9 KiB
package com.platform.utils;
|
|
|
|
import java.io.BufferedInputStream;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.Properties;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
public class ConfigPropertyReader {
|
|
private String configPath;
|
|
private volatile static ConfigPropertyReader configLoder;
|
|
|
|
private ConfigPropertyReader(String configPath) {
|
|
this.configPath = configPath;
|
|
}
|
|
|
|
public static ConfigPropertyReader Builder(String configPtah) {
|
|
if (null == configLoder) {
|
|
synchronized (ConfigPropertyReader.class) {
|
|
if (null == configLoder)
|
|
configLoder = new ConfigPropertyReader(configPtah);
|
|
}
|
|
}
|
|
return configLoder;
|
|
}
|
|
|
|
/**
|
|
* 读取文Property中的属性值
|
|
*
|
|
* @param key
|
|
* @return
|
|
*/
|
|
public synchronized String getProperty(String key) {
|
|
String value = null;
|
|
if (StringUtils.isEmpty(key))
|
|
return value;
|
|
|
|
try {
|
|
InputStream is = new BufferedInputStream(new FileInputStream(
|
|
new File(configPath)));
|
|
Properties properties = new Properties();
|
|
properties.load(is);
|
|
value = properties.getProperty(key);
|
|
} catch (FileNotFoundException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public Properties getProperties() {
|
|
Properties properties = null;
|
|
try {
|
|
InputStream is;
|
|
properties = new Properties();
|
|
is = new BufferedInputStream(new FileInputStream(new File(
|
|
configPath)));
|
|
properties.load(is);
|
|
} catch (FileNotFoundException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
return properties;
|
|
}
|
|
|
|
public String getConfigPath() {
|
|
return configPath;
|
|
}
|
|
|
|
public void setConfigPath(String configPath) {
|
|
this.configPath = configPath;
|
|
}
|
|
|
|
}
|