URL: getProtocol() : URL « javax.net « Java by API





URL: getProtocol()

/*
 * Output:
 * 
 * 
Protocol: http
Port: -1
Host: www.java2s.com
File: 
Ext:http://www.java2s.com
 */

import java.net.URL;

public class MainClass {
  public static void main(String args[]) throws Exception {
    URL hp = new URL("http://www.java2s.com");
    System.out.println("Protocol: " + hp.getProtocol());
    System.out.println("Port: " + hp.getPort());
    System.out.println("Host: " + hp.getHost());
    System.out.println("File: " + hp.getFile());
    System.out.println("Ext:" + hp.toExternalForm());
  }
}
           
       










Related examples in the same category

1.new URL(String address)
2.new URL(String protocol, String host, int port, String file)
3.URL: getFile()
4.URL: getHost()
5.URL: getPort()
6.URL: openConnection()
7.URL: toExternalForm()