0

im trying to download media files through my application for which i wrote a method which read bytes from the source file and return bytes array,

byte[] mediainfo = getMediaFile(String path);

but the problem is that when the file size will become greater than 5 or 6MB it will return outofMemory exception,please kindly give some idea how i will download big media file about 10 mb through my application, thanks.

1 Answers1

0

Creating a byte array for downloaded files is only ok if these files are small enough. For large files, I definitely recommend using the stream classes of Java. Here is an example: Android download binary file problems

Mind that you have to replace f.write(buffer); by f.write(buffer,0, len1); (as answered there) - otherwise you will get wrong data.

Community
  • 1
  • 1
mreichelt
  • 12,359
  • 6
  • 56
  • 70