Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class JavaHttpURLConnectionGetErrorStreamMethodExample1 { //Starting the main method... public static void main(String h[]) throws IOException { //starting the try block try { String link_url ; link_url="https://www.javatpoint.com"; URL obj1 = new URL(link_url); //URL Connection Created... HttpURLConnection con1 = (HttpURLConnection) obj1.openConnection(); //Http URL Connection Created... con1.setConnectTimeout(1000); con1.connect(); InputStream a; a = con1.getErrorStream(); System.out.println("Error Stream : "+a); con1.disconnect(); System.out.println("Connection disconnected"); } catch (Exception e) { System.out.println( e); } } }
Output