I guess the exception tells you  that you are over-allocating memory. There
are quite strict limits on Android, but your code would fail on any platform
(apart from a Turing machine) if the download size is large enough.You will
need to loop over the input stream with something like this (no warranty)

void downloadUrl(URL url, File destination) throws IOException {
FileOutputStream writer = null;
try {
writer = new FileOutputStream(destination);
InputStream is = url.openConnection().getInputStream();
byte[] buffer = new byte[1024];
int count = 0;
while(-1 != (count = is.read(buffer))){
writer.write(buffer, 0, count);
}
} finally {
writer.close();
}
}

HTH

Ludwig


2009/1/27 sagar.indianic <[email protected]>

>
> Hello everyone,
>
> I am trying to downlaod a file from the  net. It is an mp3 file and
> big in size. I  m able to get connection but when trying to create a
> bufffer for file, I get out of memory exception....
> please help
> its urgent...
> Code is:
> URL u = new URL("http://----------";);
>    URLConnection uc = u.openConnection();
>  int contentLength = uc.getContentLength();
> InputStream raw = uc.getInputStream();
>    InputStream in = new BufferedInputStream(raw);
>    byte [] data=new byte[contentLength];    //getting outofmemory
> exception here..
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to