download file exception handling
<p>In my application I download several critical files from  a server, and I want to write some code that handles the case where the a file download didn't complete for a reason or other ,to retry downloading it at next startup. The function that downloads a file at a time however throws only MalformedURLException and IOException , but if these exceptions are thrown that means that the download didn't even begin. How should I arrange things so I can treat the case where a download failed , even if it began ? </p>

<pre><code>void download(String file) throws MalformedURLException ,IOException 
{

        BufferedInputStream getit = new BufferedInputStream(new URL(file).openStream());
        FileOutputStream saveit = new FileOutputStream(DOWNLOAD_PATH+fileName+"."+ZIP_EXTENSION);
        BufferedOutputStream bout = new BufferedOutputStream(saveit,1024);
        byte data[] = new byte[1024];
        int readed = getit.read(data,0,1024);
        while(readed != -1)
        {
            bout.write(data,0,readed);
            readed = getit.read(data,0,1024);
        }
        bout.close();
        getit.close();
        saveit.close();

}
</code></pre>
