先得到Runtime rt=Runtime.getRuntimee()对象.]
然后应用rt中的exec方法.
如rt.exec(String cmd);
cmd:完整的命令行.如:aaa.exe -ccc
public Process exec(String[] cmdarray,
String[] envp)
throws IOException
Executes the specified command and arguments in a separate process with the specified environment.
Given an array of strings cmdarray, representing the tokens of a command line, and an array of strings envp, representing "environment" variable settings, this method creates a new process in which to execute the specified command. If envp is null, the subprocess inherits the environment settings of the current process.
Parameters:
cmdarray - array containing the command to call and its arguments.
envp - array of strings, each element of which has environment variable settings in format name=value.
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.
NullPointerException - if cmdarray is null.
IndexOutOfBoundsException - if cmdarray is an empty array (has length 0).
IOException - if an I/O error occurs
See Also:
Process, SecurityException, SecurityManager.checkExec(java.lang.String)--------------------------------------------------------------------------------
记得要给分啊.呵呵
然后应用rt中的exec方法.
如rt.exec(String cmd);
cmd:完整的命令行.如:aaa.exe -ccc
public Process exec(String[] cmdarray,
String[] envp)
throws IOException
Executes the specified command and arguments in a separate process with the specified environment.
Given an array of strings cmdarray, representing the tokens of a command line, and an array of strings envp, representing "environment" variable settings, this method creates a new process in which to execute the specified command. If envp is null, the subprocess inherits the environment settings of the current process.
Parameters:
cmdarray - array containing the command to call and its arguments.
envp - array of strings, each element of which has environment variable settings in format name=value.
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.
NullPointerException - if cmdarray is null.
IndexOutOfBoundsException - if cmdarray is an empty array (has length 0).
IOException - if an I/O error occurs
See Also:
Process, SecurityException, SecurityManager.checkExec(java.lang.String)--------------------------------------------------------------------------------
记得要给分啊.呵呵
解决方案 »
- 关于继承的一个问题
- fileinputstream如何构造
- JLabel只能显示文字不能显示图标,是为什么呢?
- !!!FileInputStream如何用jar文件里的jpg图像?!!!!!!!!!!!1
- RandomAccessFile能不能创建文件
- 如何在winme环境小设置jdk1。3。1的开发环境
- 怎样解决这个中文问题?(关于URL)??????????????????????
- 编译参数问题,初学者的问题,请多帮忙
- 急问!关于jdbc访问数据库!
- 为什么没人理我的问题?就因为我给的分低吗?你们这些高手也太见钱眼开了吧
- windows xp下怎么安装jdk??(高分求助!!)
- 在java里如何调用DLL
得到一个Process对象,代表你执行的程序.
用这个对象的getInputStream()方法,取得输入流,就可以读到返回值了.
其他请参看API文档.
比如说调用notepad,ping 127.0.0.1 的到返回值
不过我还会给你分的。等一会有更好的方法时。
再问,是不是调用的程序,必须由,java来结束?
Runtime rt=Runtime.getRuntimee();
rt.exec("C:\\Program Files\\Accessories\\Wordpad D:\\xxxx.txt");