HttpURLConnection GetErrorStream() Example

Returns the error stream if the connection failed


HttpURLConnectionclass GetErrorStream() method example. This example shows you how to use GetErrorStream() method.This method Returns the error stream if the connection failed but the server sent useful data nonetheless.

Here is the code:-
/* 
 * @Program that Returns the error stream if the connection failed but the 
    server sent useful data nonetheless.
 * GetErrorStream.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */
import java.io.*;
import java.net.*;

public class GetErrorStream {

    public static void main(String args[]) throws Exception {
        URL url = new URL("http://google.com");
        HttpURLConnection connection = (HttpURLConnectionurl.openConnection();
        InputStream i = connection.getErrorStream();
        if (i != null) {
            System.out.println("connection failed !!!");
            if (i.available() != 0) {
                System.out.println(i.read());
            }
        else {
            System.out.println("connection not failed");
        }
           
    }
}

Output of the program:-
 connection not failed

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

HOME | COPYRIGHT | CONTACT US