您的位置:首页 > 运维架构

读取properties文件和属性

2013-04-26 18:16 337 查看
public class PropertiesUtils {
/**
* 配置文件.
*/
private Properties prop;
/**
* 输入流.
*/
private InputStream is;

/**
* 构造函数.
*
* @param filename
*            以“/”开头,根据工程项目路径读取
*/
public PropertiesUtils(String filename) {
prop = new Properties();
is = getClass().getResourceAsStream(filename);
try {
prop.load(is);
} catch (IOException e) {
System.out.print(e.getMessage());
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

/**
* 读取属性.
*
* @param propertyName
* @return
*/
public String getProperties(String propertyName) {
return prop.getProperty(propertyName);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: