open Link vis default browser - Java Network

Java examples for Network:Http

Description

open Link vis default browser

Demo Code


//package com.java2s;
import java.awt.Desktop;

import java.net.URL;

public class Main {
    public static void main(String[] argv) throws Exception {
        String url = "java2s.com";
        openLink(url);//from w ww.  j a v a 2 s .  com
    }

    public static void openLink(String url) {
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop
                .getDesktop() : null;

        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(new URL(url).toURI());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Related Tutorials