如何在 java.util.Properties 中引用另一个属性? [英] How to reference another property in java.util.Properties?

查看:38
本文介绍了如何在 java.util.Properties 中引用另一个属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 属性文件可以引用其他属性文件吗?

## 定义输入文件的默认目录dir.default=/home/data/in/dir.proj1=${dir.default}p1dir.proj2=${dir.default}p2dir.proj3=${dir.default}p3

这可能吗?

解决方案

Chris Mair 的 XProperties 类可能是一个很好的起点.

<块引用>

您可以在属性值的任何位置替换常量,甚至可以在一个值中包含多个常量,如下例所示:

CONST_1 = 鞋子和船CONST_2 = 封蜡SomeValue = {CONST_1} 和 {CONST_2}

<块引用>

在这个例子中,SomeValue"属性评估为鞋子和船舶和密封蜡".

Can Java properties file reference other properties file?

## define a default directory for Input files  
dir.default=/home/data/in/

dir.proj1=${dir.default}p1
dir.proj2=${dir.default}p2
dir.proj3=${dir.default}p3

Is this possible?

解决方案

Chris Mair's XProperties class may be a good starting point.

You can substitute a constant anywhere in the property value, and even have more than one constant within a value, as in the following example:

CONST_1 = shoes and ships
CONST_2 = sealing wax
SomeValue = {CONST_1} and {CONST_2} 

In this example, the "SomeValue" property evaluates to "shoes and ships and sealing wax."

这篇关于如何在 java.util.Properties 中引用另一个属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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