【发布时间】:2019-02-05 10:10:37
【问题描述】:
我的代码:
public static InputStream input = null;
public static Properties prop = new Properties();
static public void getConstants(){
Constants constants = new ConstantsEng();
try {
input = CLASS_NAME.class.getClassLoader().getResourceAsStream("FILE_NAME.properties");
prop.load(input);
} catch (IOException e) {
e.printStackTrace();
}
public static String SOURCE = prop.getProperty("SOURCE");
public static String SOURCES = prop.getProperty("SOURCES");
public static String DESTINATION = prop.getProperty("DESTINATION");
public static String DESTINATIONS = prop.getProperty("DESTINATIONS");
FILE_NAME.properties
SOURCE=Source
SOURCES=${SOURCE}s
DESTINATION=Destination
DESTINATIONS=${DESTINATION}s
字符串在渲染时会显示占位符:
我想在我的 .properties 文件中重用字符串,但此代码不起作用。有没有办法解决它,还是我犯了一个错误?
当我获取时:
public static String SOURCES = prop.getProperty("SOURCES");
我期待“来源”作为输出。
【问题讨论】:
-
你能发布预期的输出而不是发布图片吗?
-
当我获取 public static String SOURCES = prop.getProperty("SOURCES");我期待“来源”作为输出。
标签: java properties-file application.properties