我已经阅读了许多关于避免在 java 中进行硬编码的文章。但是无法清楚地了解如何将其应用于我的要求。在做了一些研究之后,我提出了这个问题。下面是我的代码片段。在那我想避免路径名的硬编码Process pr = rt.exec()
。关于如何做的任何建议?
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:\\File\\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;
}
}