title: how to check url connection status in java
body: <p>I am executing the get request in java using "URLConnection". I am sending the get requests to different Ip addresses in order to generate the alarm.If the url is valid it made the connection and read the data return from the url, but it doesnt return any thing if the connection is unsuccessful. I need to know is there any isconnect method in urlconnection because i need to set a flags for my program and I couldn't find any way to determine the unsuccessful connection, I am using the following code:
             URL url = new URL(address);</p>
  
  <pre><code>         URLConnection conn = url.openConnection();
           conn.setConnectTimeout(20);
           //bool flag=conn.isconnect()
  
  
          BufferedReader br = new BufferedReader(new 
          InputStreamReader(conn.getInputStream()));              
         System.out.println("connected"); 
  
        while ((line = br.readLine()) != null)
        {
          result += line;
  
        }
        //if (flag){triggered the ip}
        //if (!flag){not triggered}
  </code></pre>
  
  <p>I need to execute the commented if conditions, but I am struggling on it  because the program doesnt reach after the "bufferedReader br" statement if the ip is invalid or if it is not present.</p>