Java: Memory efficient ByteArrayOutputStream
问题 I've got a 40MB file in the disk and I need to "map" it into memory using a byte array. At first, I thought writing the file to a ByteArrayOutputStream would be the best way, but I find it takes about 160MB of heap space at some moment during the copy operation. Does somebody know a better way to do this without using three times the file size of RAM? Update: Thanks for your answers. I noticed I could reduce memory consumption a little telling ByteArrayOutputStream initial size to be a bit