Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Network Print the URL of a URLConnection

Related Tutorials


 
 

Share on Google+Share on Google+

Print the URL of a URLConnection

Advertisement
In this section we are going to describe, how to retieve the value of the URL assign to the url object.

Print the URL of a URLConnection

     

In this section we are going to describe, how to retieve the value of the URL assign to the url object. Here is the complete code of the program in which first of all we establish a connection then display it. In the example we open the connection by using the openConnection() method. After that we use the getURL() which returns the value of this URLConnection's URL field to display the assign URL. 


Here is the Output of the Example :

import java.net.*;
import java.io.IOException;

public class printURLConnection {
  public static void main(String args[]) {

  URL url;
  URLConnection uc;

  try {
  url = new URL("http://roseindia.net/");
  try {
  uc = url.openConnection();
  System.out.println(uc.getURL());
  }
  catch (IOException exp) {
  System.err.println(exp);
  }
  }
  catch (MalformedURLException exp) {
  System.err.println(exp);
  }
  }
}

Here is the Output of the Example :

C:\roseindia>javac printURLConnection.java

C:\roseindia>java printURLConnection
http://roseindia.net/

Download of this example.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 19, 2008

Related Tutorials

Discuss: Print the URL of a URLConnection  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
md aleem
August 7, 2012
website

open website address
DMCA.com