Hello folks,
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
FileOutputStream(outputFile));
byte buf[] = new byte[BUFFER_SIZE];
int numBytesRead;
do
{
numBytesRead = stream.read(buf);
if (numBytesRead > 0)
{
fos.write(buff, 0, numBytesRead);
}
} while (numBytesRead > 0);
fos.flush();
fos.close();
stream.close();
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
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe from this group, send email to
android-developers+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.