Intro
This example, will demonstrates how to get URL properties such as URL port, URL host, URL path, and etc using Java Network programming.
Example
package com.freesamplecode.java.networking; import java.net.MalformedURLException; import java.net.URL; public class GetURLPropertiesDemo { public static void main(String[] args){ URL url = null; try { url = new URL("http://free-samplecode.blogspot.com/p/java.html"); System.out.println("Protocol : "+url.getProtocol()); System.out.println("Host : "+url.getHost()); System.out.println("Port : "+url.getPort()); System.out.println("Query : "+url.getQuery()); System.out.println("Path : "+url.getPath()); System.out.println("User Info : "+url.getUserInfo()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Output
Protocol : http Host : free-samplecode.blogspot.com Port : -1 Query : null Path : /p/java.html User Info : null
0 comments: