Java调用exe文件

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

 

public class Demo
{ 
      public static void main(String args[])
      { 
            Runtime rn=Runtime.getRuntime(); 
            Process p=null; 

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

 

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

 

public class Demo
{ 
    public static void main(String args[])
    { 
        Runtime rn=Runtime.getRuntime(); 
        Process p=null; 

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


public class ProcessDemo
{
    public static void main(String args[])
    {
        try 
        {
            //调用系统计算器
            Runtime.getRuntime().exec("calc");
            //打开系统记事本
            Runtime.getRuntime().exec("notepad");
            //打开html
            Runtime.getRuntime().exec("explorer.exe C:\\soft\\jdk及doc文档\\html\\zh_CN\\api\\index.html");
        }
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }  	
    }
}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值