你有几件事要尝试:
java PROPERTIES
private Properties _properties;
private void init(){
_properties = new Properties();
InputStream configurationFileIS = PropertiesConfigurationHandler.class.getClassLoader().getResourceAsStream(CONFIGURATION_FILE);
_properties.load(configurationFileIS);
}
public String getStringValue(String path) {
return _properties.getProperty(path);
}
和属性文件将类似
an.element.to.be.configured.like.a.path=/dev/null
但您也可以使用SPRING CONTEXT
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
WEB-INF/classes/config/properties/database.properties
classpath:config/properties/database.properties
并且将以这种方式访问database.properties中的元素
"${jdbc.username}"
–
为你的具体问题.
您可以创建文件constants.properties
executable.run=C:\\server\\rd.exe
incoming.file=C:\\file.lic
executable.params=-z
log.file=C:\\File\\log.txt
然后在init之后调用getStringValue:
String executable = getStringValue("executable.run");
String filein = getStringValue("incoming.file");
String params = getStringValue("executable.params");
String log = getStringValue("log.file");
然后你可以使用rt.exec而不是使用硬编码字符串,你可以使用之前检索的字符串.