networking_url_conection.htm
 
  • A URL has two main components:
    • Protocol identifier: File or http://
    • Resource name: xyz.com or xyz.txt
 

import java.lang.reflect.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class Test_this {
static public void main( String[] args )throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//http://frontiersoft.net/welcome.html
//http://manas6:80/myphp
System.out.print("Type URL: ");
String str = "";
str = br.readLine();
process_this pt = new process_this();
pt.method_parse_url(str);

}
}
class process_this
{
public void method_parse_url(String str)throws IOException
{
URL aURL = new URL(str);
URLConnection ucon = aURL.openConnection();
System.out.println("Date : = " + new Date(ucon.getDate()));
System.out.println("protocol = " + aURL.getProtocol());
System.out.println("Connection type = " + ucon.getContentType());
System.out.println("authority = " + aURL.getAuthority());
System.out.println("Expiration = " + ucon.getExpiration());
System.out.println("Last Modified = " + ucon.getLastModified());
System.out.println("host = " + aURL.getHost());
System.out.println("port = " + aURL.getPort());
System.out.println("path = " + aURL.getPath());
System.out.println("query = " + aURL.getQuery());
System.out.println("filename = " + aURL.getFile());
System.out.println("ref = " + aURL.getRef());
}

}
 

Info as a file protocol