Hello. There is a code that downloads a file from the Internet.

private static void downloadUsingStream(String urlStr, String file) throws IOException{ URL url = new URL(urlStr); BufferedInputStream bis = new BufferedInputStream(url.openStream()); FileOutputStream fis = new FileOutputStream(file); byte[] buffer = new byte[1024]; int count=0; while((count = bis.read(buffer,0,1024)) != -1) { fis.write(buffer, 0, count); } fis.close(); bis.close(); } 

A couple of weeks ago, the file was downloaded as it should. And today I noticed that it does not swing. I began to understand, there are no errors, but I found out that for some reason 180Kb of 9Mb is downloaded. What am I doing wrong and how to solve the problem?

    1 answer 1

    In general, problems can be many. The simplest ones that I see, based on the fact that everything worked:

    1. Could run out of memory in the phone.
    2. Maybe something is wrong with the file on the Internet.
    • Understood. Just the file that I want to download not to this address but with a redirect - Ivan
    • @Ivan, that is my second option. Accept the answer, if it helped you solve the problem. - Rostislav Dugin