心意乱
2018-11-30
1377浏览量
编写 .properties
文件
key
=value
] 格式=
符号是允许有空格的, 程序读取时会去除 =
左右空格定义类获取.peroperties
文件中的值
Class
对象Class
对象获取 ClassLoader
类加载器getResourceAsStream()
方法获取字节流Properties
集合, 调用集合中的 load(inputStream)
来读取文件Properties
集合中的 getProperty("key")
来获取对于的值编写
.properties
文件
key=value
mark=markValue
info=infoVlaue
定义类获取
.peroperties
文件中的值
public static void main(String[] args) throws IOException {
InputStream inputStream = PropertiesDemo.class.getClassLoader().getResourceAsStream("info.properties");
Properties properties = new Properties();
properties.load(inputStream);
System.out.println("key:[" + properties.getProperty("key") + "]");
System.out.println("mark:[" + properties.getProperty("mark") + "]");
System.out.println("info:[" + properties.getProperty("info") + "]");
}
那么执行程序将输出结果为:
key:[value]
mark:[markValue]
info:[infoVlaue]
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。