讓我們假設我有一個監聽器按鈕「.BAT」文件中的JAVA
public class Visualizer1 implements ActionListener {
public void actionPerformed(ActionEvent a) {
try {
Runtime rt2 = Runtime.getRuntime();
Process p = rt2.exec("visualizer/vis1.exe");
InputStream in = p.getInputStream();
OutputStream out = p.getOutputStream();
InputStream err = p.getErrorStream();
p.destroy();
} catch (Exception exc) {/* handle exception */
}
的‘vis1.exe’將執行,沒有任何問題,它會打開 ,但如果我有一個應用程序帶有「.bat」擴展名,就像它是(vis1.bat)一樣,它不會打開。 注:.bat擴展名是可執行文件
閱讀:http://stackoverflow.com/questions/615948/how -do-i-run-a-batch-file-from-my-java-application – Obicere
嘗試通過「c:\ windows \ system32 \ cmd.exe your.bat」或者「%comspec%your.bat」啓動,其中%comspec%是一個環境變量,應該包含用於cmd.exe的路徑。蝙蝠執行 – Dodge
請爲我編碼。我的「vis1」文件位於名爲「home」的文件夾中 –