InputStream throwing SocketTimeOutException on read when file is not available
===

Trying to read some image files from a server and using socket programming for the same.

But I am getting socketTimeOut exception when there is no file exist. Not only that loosing the connection to the server.

How can I avoid loosing the connection to the server when there is no file exist.

    InputStream inputStream = new BufferedInputStream(socket().getInputStream());
 
    int i = -1;
    while ((i = bufferedInputStream.read()) != -1) {
    byteArrayOutputStream.write(i);
    }

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.

Thanks

