Try increasing the amount of memory that's allocated to the JVM by using the JVM parameter -Xmx
(type
java -X to get the help details for the -X** commands)
Realize that for several of those methods (such as StringBuffer) you're trying to read in the entire file and store it in a StringBuffer, and then write it back out, so the amount of memory the JVM has needs to be large enough that it can hold the entire file, so maybe try something like:
java -Xmx512m com.blah.myProgram
that will allocate 512 MB to the JVM.