得到配置资源的一般做法--CLASS.getResourceAsStream(String resource)
敬业的IT人
互联网
佚名
2008-5-16 12:34:06
protected InputStream getConfigurationInputStream(String resource) throws HibernateException {
InputStream stream = Environment.class.getResourceAsStream(resource);
if (stream==null) {
throw new Exception(resource " not found");
}
return stream;
}
client应该这么写:
//hibernate.cfg.xml位于classes目录下(classPath目录)
InputStream stream = getConfigurationInputStream("/hibernate.cfg.xml");
如果资源是.property的配置文件,则可以这么装载
Properties property=new Properties();
property.load(stream);
总起来可以这么写:
public Properties getPropFromFile(String filePath){
InputStream stream = Environment.class.getResourceAsStream(resource);
if (stream==null) {
throw new Exception(resource " not found");
}
Properties property=new Properties();
property.load(stream);
return stream;
}
- 最新文章
- weblogic——远程/近程调用EJB的方法总结[05-16]
- JDBC基础知识(1)[05-16]
- 数据结构Java 版 2.1 队员管理小程序 原创[05-16]
- 对极限编程四个核心的理解(二)[05-16]
- Singleton设计模式介绍[05-16]
- 在对象OR映射中采用对象存储范式代替关系存储是否可行?[05-16]
- 相关文章
