1.调用其他程序,好像只能是exe等可执行程序,
public class Exec {
public static void main(String[] args) {
try{
Process p=Runtime.getRuntime().exec("mspaint");
p.waitFor();
}catch(Exception e){
}
}
} |
其中引号内mspaint是系统自带的画图板程序,当然还可以写其它自系统自带程序比如notepad等以及自己写的exe程序等等
2.用同样的方法,可以指定程序来打开文件:
public class Exec {
public static void main(String[] args) {
try{
Process p=Runtime.getRuntime().exec
("c:\\Program Files\\MicrosoftOffice\\office\\winword.exe d:\\a.doc");
p.waitFor();
}catch(Exception e){
}
}
} |
上例中用word程序来打开D盘根目录下的a.doc文件 |