URL openConnection Example

URL class openConnection example. This example shows you how to use openConnection method.


URL class openConnection example. public URLConnection openConnection() throws IOException Returns a URLConnection object that represents a connection to the remote object referred to by the URL.

/*
 * @ # OpenConnection.java
 * A class repersenting use to openConnection method 
 * of URL class in java.net package
 * version 24 June 2008
 * author Rose India 
 */

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

public class OpenConnection {

    public static void main(String args[]) throws Exception {

        URL url = new URL("http://localhost:8080/programs/index.html");
        URLConnection uRLConnection = url.openConnection();

        BufferedReader br = new BufferedReader(
                new InputStreamReader(uRLConnection.getInputStream()));
        String inputLine;

        while ((inputLine = br.readLine()) != null
            System.out.println(inputLine);
    }
}

Output
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Hi!</h2>
     </body>
</html>

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US