/**
* 读取配置文件
*/
public static Properties loadParams(String file) throws IOException {
Properties prop = new Properties();
ResourceBundle bundle = ResourceBundle.getBundle(file);
String key = null;
for (Enumeration<String> enuma = bundle.getKeys(); enuma
.hasMoreElements(); ) {
key = enuma.nextElement();
prop.put(key, bundle.getObject(key));
}
return prop;
}
/**
* 获取外部配置文件
*/
public static Properties loadOutParams(String file) throws IOException {
Properties prop = new Properties();
String proFilePath = System.getProperty("user.dir") + File.separator + file;
InputStream in = new BufferedInputStream(new FileInputStream(proFilePath));
ResourceBundle bundle = new PropertyResourceBundle(in);
String key = null;
for (Enumeration<String> enuma = bundle.getKeys(); enuma
.hasMoreElements(); ) {
key = enuma.nextElement();
prop.put(key, bundle.getObject(key));
}
return prop;
}
=======================================================================
Properties pro = Utilties.loadOutParams("/config/config.properties");
username = pro.getProperty("username");
password = pro.getProperty("pwd");
读取Properties 文件
最新推荐文章于 2023-07-10 21:41:45 发布