我已经阅读了很多关于避免java中硬编码的文章。但无法弄清楚如何将其应用于我的要求。在做了一些研究之后,我会问这个问题。以下是我的代码片段。因为我想避免Process pr = rt.exec()中的路径名的硬编码。关于如何执行它的任何建议。提前感谢。如何避免Java中的硬编码
public class StartUp {
String executable = getStringValue("executable.run");
String filein = getStringValue("incoming.file");
String params1 = getStringValue("executable.params1");
String params2 = getStringValue("executable.params2");
String log = getStringValue("log.file");
String ss = "Started";
public String startCommand() throws IOException, InterruptedException{
Runtime rt = Runtime.getRuntime();
//Process pr = rt.exec("C:\\server\\rd.exe -a C:\\file.lic -z[+]
// C:\文件\ log.txt的“);
Process pr = rt.exec(executable+" "+params1+" "+filein+" "+params2+" "+log);
BufferedReader input = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
String line=null;
StringBuffer start= new StringBuffer();
while((line=input.readLine()) != null) {
start.append("ServerStarted" + line + "\n");
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
return line;
//return start.toString();
}
private static String getStringValue(String string) {
return string;
}
}
什么需要在什么情况下 –