You are here: Home / Topics / Program to display all parts of URL in Java

Program to display all parts of URL in Java

Filed under: Java on 2023-10-25 06:48:59

// Program to display all parts of URL.

import java.net.*;

class URLDemo
{
public static void main( String args[ ] ) throws Exception
{
 URL ob = new URL("http://www.bethedeveloper.com/java/");
 System.out.println(" Protocol : " + ob.getProtocol());
 System.out.println(" Host : " + ob.getHost());
 System.out.println(" File : " + ob.getFile());
 System.out.println(" Port : " + ob.getPort());
 System.out.println(" Path : " + ob.getPath()); 
 System.out.println(" URL : " + ob.toString()); 
}
}

 

Output:

Protocol : http
Host : www.bethedeveloper.com
File : /java/
Port : -1
Path : /java/
URL : http://www.bethedeveloper.com/java/


About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.