使用runtime可以调用操作系统中的底层命令。
例子:
package com.sand.test;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestStartExe {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
BufferedReader bf = null;
Process p = null;
try{
String file = "D:\\宸ュ叿杞欢\\Notepad++\\notepad++.exe";
//run.exec("cmd.exe /c start " + file);
p = run.exec("C:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQScLauncher.exe");
bf = new BufferedReader(new InputStreamReader(p.getInputStream()));
String msg = null;
while((msg = bf.readLine()) != null){
System.out.println(msg);
}
System.out.println(p.exitValue());
}catch(Exception e){
e.printStackTrace();
}finally{
if(bf != null){
try {
bf.close();
p.destroy();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}