Getting java gui to open a webpage in web browser

后端 未结 4 1550
野的像风
野的像风 2020-11-28 10:20

I am trying to get a java gui to open a web page. So the gui runs some code that does things and then produces a html file. I then want this file to open in a web browser (p

4条回答
  •  执笔经年
    2020-11-28 10:55

    Ya, But if you want to open the webpage in your default web browser by a java program then you can try using this code.

    /// file OpenPageInDefaultBrowser.java
    public class OpenPageInDefaultBrowser {
       public static void main(String[] args) {
           try {
             //Set your page url in this string. For eg, I m using URL for Google Search engine
             String url = "http://www.google.com";
             java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
           }
           catch (java.io.IOException e) {
               System.out.println(e.getMessage());
           }
       }
    }
    /// End of file
    

提交回复
热议问题