01.public static void main(String[] args) throws IOException {
02. openWindowsExe();
03. openExe();
04. openFile();
05. }
06. //用 Java 调用windows系统的exe文件,比如notepad,calc之类
07.public static void openWindowsExe() {
08. Runtime rn = Runtime.getRuntime();
09. Process p = null;
10. try {
11. String
command = "notepad";
12. p = rn.exec(command);
13. } catch (Exception e) {
14. System.out.println("Error win exec!");
15. }
16.}
17. //调用其他的可执行文件,例如:自己制作的exe,或是 下载 安装的软件.
18.public static void openExe() {
19. Runtime rn = Runtime.getRuntime();
20. Process p = null;
21.
22. try {
23. p = rn.exec("\"D:/
QQ.exe\"");
24.
25. } catch (Exception e) {
26. System.out.println("Error exec!");
27. }
28.}
29.
30. //打开其他任意格式的文件,比如txt,word等
31.public static void openFile() {
32. Runtime rn = Runtime.getRuntime();
33. Process p = null;
34. String cmd="rundll32 url.dll FileProtocolHandler file://D:/help.doc ";
35. try {
36. p = rn.exec(cmd);
37. } catch (Exception e) {
38. System.out.println("Error exec!");
39. }
40.}