Java调用系统默认浏览器打开URL 及执行CMD命令
public static void runBroswer(String url) {
Desktop desktop = Desktop.getDesktop();
if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {
URI uri = null;
try {
uri = new URI(url);
} catch (URISyntaxException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
desktop.browse(uri); // 使用系统默认的浏览器执行这个url
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Runtime.getRuntime().exec("taskkill /F /IM Iexplore.exe");
try {
Runtime.getRuntime().exec("taskkill /IM 360se.exe"); // 因为我系统默认的是360,然后关闭浏览器
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
runBroswer("https://www.baidu.com");
}
本文来自博客园,作者:IT情深,转载请注明原文链接:https://www.cnblogs.com/wh445306/p/16751852.html