【发布时间】:2015-10-30 13:53:34
【问题描述】:
以下代码不完整,但我的问题主要集中在方法 processConfig() 上。它从文件中读取属性,我想将这些属性移交给方法 replaceID()。当 processConfig 的内容在 main() 方法中时,它已经工作了。但现在我想把这段代码放到它自己的方法中。移交属性的最佳方式是什么(我保存在字符串中,如 difFilePath)。我对 OO 编程不太熟悉,想理解这个概念。感谢您的帮助。
public class IDUpdater {
....
public static void main(String[] args) throws Exception {
//Here I want to call the variables from processConfig() to make them available for replaceID(...)
replaceID(difFilePath, outputDifPath, encoding);
}
public static void replaceID(String difFilePath, String outputDifPath, String encoding) throws Exception{
return record;
}
public void processConfig(){
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
} catch (Exception e) {
logger.error("File 'config.properties' could not be found.");
}
try {
prop.load(input);
} catch (Exception e) {
logger.error("Properties file could not be loaded.");
}
String difFilePath = prop.getProperty("dif_file_path");
String outputDifPath = prop.getProperty("output_dif_path");
String encoding = prop.getProperty("encoding");
}
}
【问题讨论】: