Java调用.exe文件

package cn.sos.psasps;

public class TestExe {

public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();
    test01(runtime);
    openWinExe(runtime);

}

//调用其它的可执行文件,列如:自己制作的exe,或是下载安装的软件
public static void test01(Runtime runtime){
    Process p = null;
    try {
        p = runtime.exec("\"D:/wmlf.exe\"");
    } catch (Exception e) {
        System.out.println("Error exec!");
    }

}
//用Java调用Windows系统的exe文件
public static void openWinExe(Runtime runtime){

    Process p = null;
    try {
        String command = "qq";
        p = runtime.exec(command);

    } catch (Exception e) {
        System.out.println("Error win exec!");
    }
}

}
注:如果运行的是计算型的.exe文件.必须把参数文件拷贝到classpath下才能进行运算.

你可能感兴趣的:(exe)