您可以在这里快速查找:


 
您的位置: 编程学习 > java教程 > 200601
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

得到配置资源的一般做法--CLASS.getResourceAsStream(String resource)

webwork

 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;

}