4

I am trying to create a zip file with collection of files i used java.nio.Files class to do this... Files.copy( toBeAdded,internalTargetPath, StandardCopyOption.REPLACE_EXISTING );

it running out of heap memory due to file size is around 670MB, so is their anyway to do copy with chunks

JAVAC
  • 1,132
  • 3
  • 15
  • 35
  • found a solution? – Fabio Ebner Jan 29 '18 at 20:07
  • it depends on the destination stream, for instance for HTTP streams you need to set a parameter to avoid storing the full file in memory https://stackoverflow.com/questions/2082057/outputstream-outofmemoryerror-when-sending-http – csanchez Apr 09 '18 at 14:47

1 Answers1

0

You can include commons-io, specifcally, the copyLarge method does the trick:

FileOutputStream internalTargetPathStream = new FileOutputStream(internalTargetPath); long size = IOUtils.copyLarge(sourceStream, internalTargetPathStream);

hd1
  • 32,598
  • 5
  • 75
  • 87