java Runtime 中 的一些功能(创建一个进程 打开某个软件和关闭)

来源:互联网 发布:重要经济数据公布时间 编辑:程序博客网 时间:2024/05/18 18:03

1.打开某个软件

try {            String s = "notepad.exe";            //这个只是打开某个软件            Runtime.getRuntime().exec(s);            //用某个软件打开某个文件            String f="notepad.exe c:\\1.txt";            Runtime.getRuntime().exec(f);        }        catch (Exception e)        {            System.out.println("!");        }


2.打开并且把它关掉

try {            String s = "notepad.exe";            //打开某个软件            Process p=Runtime.getRuntime().exec(s);            Thread.sleep(3000);                        //杀掉这个进程            p.destroy();        }        catch (Exception e)        {            System.out.println("!");        }


原创粉丝点击