Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1894814
  • 博文数量: 606
  • 博客积分: 9991
  • 博客等级: 中将
  • 技术积分: 5725
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-17 19:07
文章分类

全部博文(606)

文章存档

2011年(10)

2010年(67)

2009年(155)

2008年(386)

分类:

2008-07-30 21:48:49

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

public class Demo1 {
    public static void runExe(){
        String name = "notepad";
        Runtime rn=Runtime.getRuntime();
        Process p=null;

        try{
        p=rn.exec(name);
        }catch(Exception e){
        System.out.println("Error exec!");
        }     
    }
}

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

public class Demo2 {
    public static void runExe(){
        Runtime rn=Runtime.getRuntime();
        Process p=null;

        try{
        p=rn.exec("D:\\storm.exe");
        }catch(Exception e){
        System.out.println("Error exec!");
        }       
    }
}

转载:http://hi.baidu.com/coolcat_police/blog/item/96a7fe7ae6344eeb2f73b322.html

阅读(700) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~