Here we are going to explain a method for retrieve all the network information for a given URL. In the given below example we use the URL class and make a object. After creating a object we assign a new URL to it. Then we just call a getProtocol() method to retrieve the protocol, getPort() method for retrieve the port number of the URL, getHost to get the host name of that URL. Apart from all of this we can also find out the file name if we pass any file name with URL by getFile() and by toExternalForm() method is use to retreive the full name of the URL.
The given example shows all the above method in proper manner. The code of the example is as under
Here is the Code of the Example :
The out put of the above example is as under, where the
output display all the information related with the given URL.
Here is the Output of the Example :
Posted on: December 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles