Q:

Java program to open input URL in System Default Browser in Windows (input URL from command prompt)

belongs to collection: Java Most Popular & Searched Programs

0

Java program to open input URL in System Default Browser in Windows (input URL from command prompt)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Open URL in Default Browser in Java: This java program will read a URL through command line and open it into default system browser.

package com.includehelp;

import java.awt.Desktop;
import java.net.URL;
import java.util.Scanner;


/**
 Program to open input url in system Default browser 
 in windows (input url from command prompt)
 @author includehelp
 */
public class UrlDefaultBrowser {
    public static void main(String[] args) {
        try{
            Scanner sc  =   new Scanner(System.in);
            System.out.println("Enter url (http://www.xyz.com) format  : ");
            String url =   sc.next();
            Desktop.getDesktop().browse(new URL(url).toURI());
        }
        catch(Exception E){
            System.err.println("Exp : "+E.getMessage());
        }
        
    }
}

Output

Enter url (http://www.xyz.com) format  : 
http://includehelp.com
(Now URL opened in your System Default Browser)

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java method to generate OTP (One Time Password) st... >>
<< Java program to get CPU Serial Number for Windows ...