×

Java Programs

Java Practice

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

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)

Java Most Popular & Searched Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.