Properties 配置文件的读取

上传人:博****1 文档编号:479700238 上传时间:2022-07-25 格式:DOCX 页数:2 大小:36.71KB
返回 下载 相关 举报
Properties 配置文件的读取_第1页
第1页 / 共2页
Properties 配置文件的读取_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《Properties 配置文件的读取》由会员分享,可在线阅读,更多相关《Properties 配置文件的读取(2页珍藏版)》请在金锄头文库上搜索。

1、Properties 配置文件的读取读取properties配置文件的方法汇总 如题,properties配置文件在项目中是经常用到的,那么读取properties配置文件的方法有哪些呢? 方法一:可以通过java.util.Properties类的load方法 1 InputStreamin=lnewBufferedInputStream(newFileInputStream(name); 2 Propertiesp=newProperties; 3 p.load(in); 方法二:利用spring来读取properties配置文件 org.springframework.beans.fac

2、tory.support.PropertiesBeanDefinitionReader 方法三:通过java.util.ResourceBundle类的getBundle方法 ResourceBundle rb = ResourceBundle.getBundle(name, 1 Locale.getDefault); 方法四:通过java.util.PropertyResourceBundle类的构造函数 1 InputStream in = new BufferedInputStream(new FileInputStream(name); 2 ResourceBundle rb = ne

3、w PropertyResourceBundle(in); 感谢luochen1314 提供的一种方法 版本二: ResourceBundle res = ResourceBundle.getBundle(baseName); baseName为 包路径/文件名(不带后缀) 比如properties文件在com.tt包下,文件名为tt.properties 则baseNamewei com/tt/tt 方法五:使用class变量的getResourceAsStream方法 1 InputStream in = JProperties.class.getResourceAsStream(name

4、); 2 Properties p = new Properties; 3 p.load(in); 方法六:通过class.getClassLoader所得到的java.lang.ClassLoader的getResourceAsStream方法 InputStream in = 1 JProperties.class.getClassLoader.getResourceAsStream(name); 2 Properties p = new Properties; 3 p.load(in); 方法七:通过java.lang.ClassLoader类的getSystemResourceAsSt

5、ream静态方法 1 InputStream in = ClassLoader.getSystemResourceAsStream(name); 2 Properties p = new Properties; 3 p.load(in); 方法八:Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream方法 1 InputStream in = context.getResourceAsStream(path); 2 Properties p = new Properties; 3 p.load(in); 暂时就找到这么多,大家有好的也可以说说.

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号