how to download large files without memory issues in java

后端 未结 4 994
悲哀的现实
悲哀的现实 2020-12-04 18:55

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

4条回答
  •  醉梦人生
    2020-12-04 19:34

    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.

提交回复
热议问题