前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用J2SE API读取Properties文件的六种方法

使用J2SE API读取Properties文件的六种方法

作者头像
用户1257393
发布2018-01-30 11:52:49
5240
发布2018-01-30 11:52:49
举报
文章被收录于专栏:精讲JAVA精讲JAVA

使用J2SE API读取Properties文件的六种方法

1。使用Java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name)); Properties p = new Properties(); p.load(in);

2。使用java.util.ResourceBundle类的getBundle()方法 示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());

3。使用java.util.PropertyResourceBundle类的构造函数 示例: InputStream in = new BufferedInputStream(new FileInputStream(name)); ResourceBundle rb = new PropertyResourceBundle(in);

4。使用class变量的getResourceAsStream()方法 示例: InputStream in = JProperties.class.getResourceAsStream(name); Properties p = new Properties(); p.load(in);

5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法 示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name); Properties p = new Properties(); p.load(in);

6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法 示例: InputStream in = ClassLoader.getSystemResourceAsStream(name); Properties p = new Properties(); p.load(in);

补充

Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法 示例:InputStream in = context.getResourceAsStream(path); Properties p = new Properties(); p.load(in);

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-11-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 精讲JAVA 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档