how to download large files without memory issues in java

后端 未结 4 996
悲哀的现实
悲哀的现实 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:31

    First you can remove the (in != null) from your while statement, it's unnecessary. Second, try removing the BufferedInputStream and just do:

    FileInputStream in = new FileInputStream(file);
    

提交回复
热议问题