title: InputStream throwing SocketTimeOutException on read when file is not available
body: <p>Trying to read some image files from a server and using socket programming for the same.</p>
  
  <p>But I am getting socketTimeOut exception when there is no file exist. Not only that loosing the connection to the server.</p>
  
  <p>How can I avoid loosing the connection to the server when there is no file exist.</p>
  
  <pre><code>InputStream inputStream = new BufferedInputStream(socket().getInputStream());
  
  int i = -1;
  while ((i = bufferedInputStream.read()) != -1) {
  byteArrayOutputStream.write(i);
  }
  </code></pre>
  
  <p>In the above code I am getting exception, when I call read() on bufferedInputStream. How can I handle this exception and loosing connection to server.</p>
  
  <p>Thanks</p>