Unit-21 Networking (URL,SOCKETS (TCP/IP),DATAGRAMS) – II

Parsing a URL…

Example : ParseURL

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import java.net.*;
import java.io.*;
public class ParseURL
{
public static void main(String[] args)throws Exception
{
URL aURL=new URL("http://java.sun.com;80/docs/books/tutorial/intro.html#DOWNLOAD");
System.out.println("protocol="+aURL.getProtocol());
System.out.println("host="+aURL.getHost());
System.out.println("filename="+aURL.getFile());
System.out.println("port="+aURL.getPort());
System.out.println("ref="+aURL.getRef());
}
}
import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args)throws Exception { URL aURL=new URL("http://java.sun.com;80/docs/books/tutorial/intro.html#DOWNLOAD"); System.out.println("protocol="+aURL.getProtocol()); System.out.println("host="+aURL.getHost()); System.out.println("filename="+aURL.getFile()); System.out.println("port="+aURL.getPort()); System.out.println("ref="+aURL.getRef()); } }
import java.net.*;
import java.io.*;
public class ParseURL
{
public static void main(String[] args)throws Exception
{
URL aURL=new URL("http://java.sun.com;80/docs/books/tutorial/intro.html#DOWNLOAD");
System.out.println("protocol="+aURL.getProtocol());
System.out.println("host="+aURL.getHost());
System.out.println("filename="+aURL.getFile());
System.out.println("port="+aURL.getPort());
System.out.println("ref="+aURL.getRef());
}
}
Output : ParseURL