Hello all, I am using the following code to add a file to a jar. It works fine for smaller files, but if the file is over 56MB, it throws and out of memory exception. Any ideas on how I can keep this from happening? thanks, -Jason
Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
You could allow the JVM to use more memory when you start your process. eg. java -Xmx500m -Xms500m MyClass The -Xmx option is maximum memory allowed and -Xms is minimum. The above specifies the use of 500MB of memory for the JVM.
Another key point would be to use a much smaller buffer, and put it in a loop so it gets reused:
This should use a lot less memory. Note also that read(byte[]) does not necessarily read all bytes in the file at once anyway - you must check the return value to be sure.
"I'm not back." - Bill Harding, Twister
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, the permaculture playing cards