ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT




ADVERTISEMENT


Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.