如何从java中启动chrome浏览器 [英] How to launch chrome browser from java

查看:1431
本文介绍了如何从java中启动chrome浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么聪明的方法可以从java类启动chrome浏览器?我问,因为我想要一个聪明的方式来启动一个应用程序,需要在浏览器上安装Chrome浏览器,并将IE浏览器作为默认浏览器并安装java 1.4.2。



感谢

解决方案

您可以像这样执行 chrome.exe

  try {
Process p = Runtime.getRuntime()。exec(\/ Program Files X86)/Google/Chrome/Application/chrome.exe\ );
p.waitFor();
System.out.println(Google Chrome启动!);
} catch(Exception e){
e.printStackTrace();
}

只要知道Chrome的安装位置即可。


Is there any smart way to launch the chrome browser from a java class? I'm asking because I would like a smart way to launch an application that required a chrome browser on a machine that has internet explorer as a default browser and java 1.4.2 installed.

thanks

解决方案

You can execute chrome.exe like this:

try {
    Process p = Runtime.getRuntime().exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");
    p.waitFor();
    System.out.println("Google Chrome launched!");
} catch (Exception e) {
    e.printStackTrace();
}

Provided you know where Chrome is installed.

这篇关于如何从java中启动chrome浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆