加载多个属性文件 [英] Loading multiple properties files

查看:53
本文介绍了加载多个属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Java 中堆叠加载的属性?例如我可以做:

Is it possible to stack loaded properties in Java? For instance can I do:

Properties properties = new Properties();

properties.load(new FileInputStream("file1.properties"));
properties.load(new FileInputStream("file2.properties"));

并从两者访问属性?

推荐答案

您可以这样做:

Properties properties = new Properties();

properties.load(new FileInputStream("file1.properties"));

Properties properties2 = new Properties();
properties2.load(new FileInputStream("file2.properties"));

properties.putAll(properties2);

注意:维护的所有密钥都是唯一的.因此,稍后加载相同键的属性将被覆盖.只是为了你的参考:)

NOTE : All the keys maintained are unique. So, the later properties loaded with same key will be overridden. Just to keep for your ref :)

这篇关于加载多个属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆