/*
* 运行可执行文件:.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);
}
}
}
java如何实现调用启动一个可执行文件,exe
最新推荐文章于 2024-07-26 03:07:50 发布