When I am trying to download a large file which is of 260MB from server, I get this error: java.lang.OutOfMemoryError: Java heap space.
I am sure my heap size i
Unfortunately you have not mentioned what type out
is. If you have memory issues I guess it is ByteArrayOutpoutStream
. So, replace it by FileOutputStream
and write the byte you are downloading directly to file.
BTW, do not use read()
method that reads byte-by-byte. Use read(byte[] arr)
instead. This is much faster.