import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
*
* @description
* @author sue
* @createdate 2016-1-15
* @projectname
* @packageclass com.xx.sue.jdbc.propertiesConfig.java
*/
public class Config {
private static Config config_ ;
private static Properties config = null;
private Config() {}
public static Config getInstance(){
if(null == config_){
config_ = new Config();
}
return config_;
}
public void init(String fileName) throws IOException {
Properties prop = new Properties();
InputStream in = null;
try {
in = new FileInputStream(new File(fileName));
prop.load(in);
} finally {
if (in != null) {
in.close();
}
}
config = prop;
}
public String getConfig(String name, String def) {
if (config == null) {
try {
init(System.getProperty("user.dir") + "\\" + "config" + "\\"
+ "jdbc.properties");
} catch (Exception e) {
e.printStackTrace();
return def;
}
}
return config.getProperty(name, def);
}
public String getConfig(String name) {
return getConfig(name, "").trim();
}
}