Download a file from a URL extremely slow, am I doing it right?

by Stormtap Studios » Tue, 23 Mar 2010 04:46:49 GMT

Sponsored Links
 Hello folks,

I tried to post this on the android-developers list twice but it
doesn't seem to ever show up and I'm not sure why that is, so I'll
post here in the hopes that someone can help me, or perhaps another
beginner like myself has also run into this problem.

I have the following code to download a binary file from a URL:

private static final int BUFFER_SIZE = 1024 * 1024;

BufferedInputStream stream = new BufferedInputStream(new URL(<MY
URL>).openStream(), BUFFER_SIZE);
BufferedOutputStream fos = new BufferedOutputStream(new
byte buf[] = new byte[BUFFER_SIZE];
int numBytesRead;
        numBytesRead =;
        if (numBytesRead > 0)
                fos.write(buff, 0, numBytesRead);
} while (numBytesRead > 0);
buf = null;

The file that I'm downloading is 6.5MB.  On the iPhone version of my
app it takes about a minute to download, maybe less on good days.  On
the Android Dev Phone 2 I'm testing on it takes 10 - 15 minutes to
download, it's EXTREMELY slow.

I am looking for any and all advice on how to speed up the download
for large binary files.

One thing I tried was to speed up the writing to the SD card by
filling up buf, and then only doing fos.write() when the buffer was
full (so roughly 6 and a half writes instead of lots of mini writes).
This seemed to have no effect on the overall process, which confirms
IMO that the slow part is definitely reading from the URL stream.

Thanks very much.

Robert Hawkey


Other Threads

1. BONDI in Andorid

Is its possible to use BONDI APIs in android ? Anyone aware of any
sample implementation.
I tried to follow the steps in,
and its not working.


2. Linking external libraries (JJIL)


I'll happily admit to being a Android Dev "noob", so bare with me.

I'm building an app that does some basic image maniplulation. I have
taken a look at JJIL, and it looks like it does many of the funcitons
I need:

So, quesiton, what is the best way to link JJIL to my Android project
in Eclipse?
I followed the documentation here, and it still errors (import JJIL
can't be resolved):

I created a new library, which appears as a "referenced libraries",
and has all the JILL subdirectories, but none of the .java files.

Can someone do me a massive favour and just break down the process?


Nick Deboar


3. How to capture long press of menu button

4. Drag and drop an image from a Gridview

5. Failed to create memory map of /dev/graphics/fb0

6. Not sure what is causing delay...

7. T-Mobile G1 won't appear in 'adb devices' list