得到配置资源的一般做法--CLASS.getResourceAsStream(String resource)
2008-04-17 14:29
483 查看
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; } |
相关文章推荐
- 使用类加载器加载配置文件/getClassLoader().getResourceAsStream()
- <转载>SpringMVC(7): 对Class.getResourceAsStream和ClassLoader.getResourceAsStream方法所使用的资源路径的解释
- 相对路径获取JAVA配置文件Class.getResourceAsStream() & ClassLoader的getResourceAsStream()
- 关于getClass().getResourceAsStream(path)跨项目取文件资源返回值为null的报错
- java中getResourceAsStream(String path)与getClassLoader.getResourceAsStream(String path)
- Java 使用getClass().getResourceAsStream()方法获取资源
- ClassLoader.getResourceAsStream(name); ---java读取配置文件
- JavaWeb基础 Class getResourceAsStream 资源路径无斜杠
- 对Class.getResourceAsStream和ClassLoader.getResourceAsStream方法所使用的资源路径的解释
- Resources.class.getResourceAsStream 获取配置的方法
- 对Class.getResourceAsStream和ClassLoader.getResourceAsStream方法所使用的资源路径的解释
- class getResourceAsStream 和 classloader getResourceAsStream获取资源的不同
- 关于class.getResourceAsStream(String name)与 class.getClassLoader().getResourceAsStream(String name)的路径
- getClass().getResourceAsStream() .获取配置文件的方法
- ClassLoader.getResourceAsStream(name);获取配置文件的方法
- ClassLoader.getResourceAsStream(name);获取配置文件的 f2ac 方法
- getResourceAsStream(String name)查找资源
- 关于class.getResourceAsStream(String name)与 class.getClassLoader().getResourceAsStream(String name)的路径
- ClassLoader.getResourceAsStream(name);获取配置文件的方法
- getClass().getResourceAsStream() .获取配置文件的方法 .