Java调用Win exe程序

一月 22, 2009 by admin  
类别:JAVA开发

java// 用Java调用windows系统的exe文件,比如notepad,calc之类

Runtime rn = Runtime.getRuntime();

rn.exec(command);

// 2.0调用其他的可执行文件,例如:自己制作的exe,或是下载安装的软件

Runtime rn = Runtime.getRuntime();

rn.exec(”"E:/QQ2008Spring.exe”");

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class transferExe {
 
/**
 
* @param args
 
*/
 
public static void main(String[] args) {
 
openWinExe();
 
openMyExe();
 
}
 
// 用Java调用windows系统的exe文件,比如notepad,calc之类
 
public static void openWinExe() {
 
Runtime rn = Runtime.getRuntime();
 
Process p = null;
 
try {
 
String command = "notepad";
 
p = rn.exec(command);
 
} catch (Exception e) {
 
System.out.println("Error win exec ");
 
}
 
}
 
// 2.0调用其他的可执行文件,例如:自己制作的exe,或是下载安装的软件
 
public static void openMyExe() {
 
Runtime rn = Runtime.getRuntime();
 
Process p = null;
 
try {
 
p = rn.exec(""E:/QQ2008Spring.exe"");
 
} catch (Exception e) {
 
System.out.println("Error my exec ");
 
}
 
}
 
}

评论

告诉我们你想说点啥...
想要有个性的头像, 到gravatar这里申请!