How to handle problem with Network Connectivity in Java
<p>I have a simple java code which gets html text from the input url:</p>

<pre><code>try {
    URL url =  new URL("www.abc.com");
    // Get the  response
    BufferedReader rd = new BufferedReader(new  InputStreamReader(url.openStream()));

      while ((line  = rd.readLine()) != null) {
      String code = code + line;

     } catch (IOException  e){}
</code></pre>

<p>I am using this code in an android project. Now the problem comes when there is no internet connectivity. The application just halts and later gives error.</p>

<p>Is there some way to break this after some fixed timeout, or even return some specific string after an exception is thrown. Can you please tell me how to do that??</p>
