您的位置:首页 > 编程语言 > Java开发

java之如何实现调用启动一个可执行文件,exe

2014-07-29 00:08 966 查看
/*
* 运行可执行文件:.exe
* 当要执行一个本地机器上的可执行文件时,
* 可以使用java.lang包中的Runtime类,首先使用Runtime类,首先
* 使用Runtime类声明一个对象
*{
*    Runtime sc =Runtime.getRuntime();
*   sc可以调用exec(String command) 方法打开本地湖区上的可执行文件或执行一个操作。
* }
*/

/*
* 不妨举列:
*    运用RUntime调用对象打开Windows平台上的记事本程序和浏览器。
*/
package DEMO;

import java.io.File;

public class test
{
public static void main(String args [])
{
try{
Runtime mt =Runtime.getRuntime();
//找到相对应的绝对路径。启动记事本文件
File  myfile =new File("c:\\Windows","Notepad.exe");
mt.exec(myfile.getAbsolutePath());
//创建新的文件路径,启动ie浏览器
myfile = new File("c:\\program Files\\Internet Explorer","IEXPLORE.www.sohu.com");
mt.exec(myfile.getAbsolutePath());
}
catch(Exception e)
{
System.out.println(e);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: