File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Out of Memory exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Out of Memory exception" Watch "Out of Memory exception" New topic
Author

Out of Memory exception

Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
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>
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
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.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Out of Memory exception
 
Similar Threads
Jar compress with deep directory
how to jar the resulting .class files after compilation
creating jar file programatically
creating jar using java.util.jar
JarInputStream