The class URL represents a Uniform resource locator, which is a pointer to the Internet "resource". A resource can be a simple file or directory, or a reference to a more complex object, such as a query to a database or search engine.
URL (String spec) int port, String file) Creates a URL object based on the specified protocol, host, port number, and file.
URL Sample code:
getFile () Gets the file name for this URL. String gethost () gets the hostname of this URL (if applicable). String GetPath () int getport () obtains the port number for this URL. String Getprotocol () obtains the protocol name for this URL. OpenConnection () returns a URLConnection object that represents the connection to the remote object referenced by the URL.
eg
Importjava.net.*; Public classUrldemo { Public Static voidMain (string[] args) {//Urldemo Urldemo = new Urldemo (); Try{URL hp=NewURL ("http://www.hao123.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 ()); } Catch(Malformedurlexception ex) {System.out.println (ex.tostring ()); } }}
Output:
-1/ext:http://www.hao123.com/
Java-url class explanation