当前位置: 技术问答>java相关
请问如何在Java中调用一个我自己编写的exe程序呢?谢谢!
来源: 互联网 发布时间:2015-05-31
本文导语: 请问如何在Java中调用一个我自己编写的exe程序呢?谢谢! | Process getRuntime.exec(String command) public static Runtime getRuntime() Returns the runtime object associated with the current Java application. Most...
请问如何在Java中调用一个我自己编写的exe程序呢?谢谢!
|
Process getRuntime.exec(String command)
public static Runtime getRuntime()
Returns the runtime object associated with the current Java application. Most of the methods of class Runtime are instance methods and must be invoked with respect to the current runtime object.
Returns:
the Runtime object associated with the current Java application.
public Process exec(String command)
throws IOException
Executes the specified string command in a separate process.
The command argument is parsed into tokens and then executed as a command in a separate process. The token parsing is done by a StringTokenizer created by the call:
new StringTokenizer(command)
with no further modifications of the character categories. This method has exactly the same effect as exec(command, null).
Parameters:
command - a specified system command.
Returns:
a Process object for managing the subprocess.
Throws:
SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess.
IOException - if an I/O error occurs
摘自Jdk1.4 doc .
public static Runtime getRuntime()
Returns the runtime object associated with the current Java application. Most of the methods of class Runtime are instance methods and must be invoked with respect to the current runtime object.
Returns:
the Runtime object associated with the current Java application.
public Process exec(String command)
throws IOException
Executes the specified string command in a separate process.
The command argument is parsed into tokens and then executed as a command in a separate process. The token parsing is done by a StringTokenizer created by the call:
new StringTokenizer(command)
with no further modifications of the character categories. This method has exactly the same effect as exec(command, null).
Parameters:
command - a specified system command.
Returns:
a Process object for managing the subprocess.
Throws:
SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess.
IOException - if an I/O error occurs
摘自Jdk1.4 doc .
|
java.lang.Process pro=java.lang.Runtime.exec(String command);
|
是用java开发的exe程序吗?
如果是,可以在java中直接调用,就像使用其他类一样。
如果不是,就需要用jni来调用了。
如果是,可以在java中直接调用,就像使用其他类一样。
如果不是,就需要用jni来调用了。
|
应该是:
java.lang.Process pro=java.lang.Runtime.getRuntime().exec(String command);
吧
exec不是类方法,你要先得到它的实例
java.lang.Process pro=java.lang.Runtime.getRuntime().exec(String command);
吧
exec不是类方法,你要先得到它的实例
|
Runtime rt = Runtime.getRuntime();
Process p1;
p1 = rt.exec(@execFile);
Process p1;
p1 = rt.exec(@execFile);