Runtime类可以执行一些本地程序,如下面的执行记事本程序,
Runtime rt = Runtime.getRuntime();
rt.exec("notepad.exe");
最近在做短信程序时需要调用对方的一个c写的exe程序,需要传n个参数,根据api实现如下代码:
String[] arg = new String[7];
//其中第一个必须为你所要调用的程序,其后一次是程序要求的参数
arg[0] = "D:/AR System/sms/SMSSender_New.exe";//调用命令
arg[1] = "10.142.13.229";//eoms方ip
arg[2] = "9907";//eoms方port
//.........
arg[6]="adf";
Runtime rt = Runtime.getRuntime();
try {
Process pro = rt.exec(arg);//注意是数组啊!
} catch (IOException e) {
e.printStackTrace();
}