1. 程式人生 > >Java呼叫exe示例

Java呼叫exe示例

Java呼叫exe

  		String cmd = "D:\QQ\Bin\QQ.exe";
        try {
        	//執行exe  cmd可以為字串(exe存放路徑)也可為陣列,呼叫exe時需要傳入引數時,可以傳陣列呼叫(引數有順序要求)
            Process p = Runtime.getRuntime().exec(cmd);
            String line = null;
            br = new BufferedReader(new InputStreamReader(p.getInputStream
())); brError = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = br.readLine()) != null || (line = brError.readLine()) != null) { //輸出exe輸出的資訊以及錯誤資訊 System.out.println(line); } } catch (Exception
e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (Exception e) { e.printStackTrace(); } } }