I built/copied a download function which gets images and videos via an URL and downloads them to an Android device.
When downloading small images it's no problem. But when trying to get files with more than 2MB
(via WLAN!) it takes literally ages! About 5 minutes for an 25MB video and so on.
Any ideas what might go wrong?
Here's my code:
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();