e3002 发表于 2013-1-27 05:08:37

Runtime类的使用

Runtime类可以执行一些本地程序,如下面的执行记事本程序,
Runtime rt = Runtime.getRuntime();
rt.exec("notepad.exe");
最近在做短信程序时需要调用对方的一个c写的exe程序,需要传n个参数,根据api实现如下代码:

  String[] arg = new String;
   //其中第一个必须为你所要调用的程序,其后一次是程序要求的参数
  arg = "D:/AR System/sms/SMSSender_New.exe";//调用命令
  arg = "10.142.13.229";//eoms方ip
  arg = "9907";//eoms方port
  //.........
 arg="adf";
  Runtime rt = Runtime.getRuntime();
  try {
   Process pro = rt.exec(arg);//注意是数组啊!
  } catch (IOException e) {
   e.printStackTrace();
  }
 
 
 
页: [1]
查看完整版本: Runtime类的使用