Open Browser window from Java program

后端 未结 5 2036
小蘑菇
小蘑菇 2021-01-12 21:44

Question

I have an application written in Java. It is designed to run on a Linux box standalone. I am trying to spawn a new firefox windo

5条回答
  •  春和景丽
    2021-01-12 22:25

    If you can narrow it down to Java 6, you can use the desktop API:

    http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/

    Should look something like:

        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.BROWSE)) {
                try {
                    desktop.browse(new URI("http://localhost"));
                }
                catch(IOException ioe) {
                    ioe.printStackTrace();
                }
                catch(URISyntaxException use) {
                    use.printStackTrace();
                }
            }
        }
    

提交回复
热议问题