所以我試圖做出一個通用的應用程序,我試圖讓它有能力打開應用程序。所以,我想通過它打開一個應用程序,如果它是一個詞,但是有空格,它就不會起作用。這就是我的做法:如何使用Runtime.getRuntime()。exec()打開名稱中包含空格的應用程序?
if(textField.getText().startsWith("application open")){
try {
String string1 = textField.getText().substring(17, textField.getText().length());
Runtime.getRuntime().exec("open /Applications/\"" + string1 + "\".app");
textArea.append("Opening application " + string1 + "..." + newline);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
如果有人能幫助我,那太棒了! 在此先感謝, Howard Stark
密切相關的HTTP解釋://stackoverflow.com/questions/7134486/how-to-execute-command-with-parameters – Raedwald