This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi, I have a really big file. I want to search for a particular pattern within this file and replace that with another text. I tried the following: 1. Used StringBuffer to load file contents to do a replace. Causes out of memory error 2. Finding the filePointer for the pattern in a random access file and doing raf.writeChars . Overwrite exixting contents instead of inserting 3. Taking the portion before the pattern , the pattern and the portion after the pattern and putting in a separate file also wont work cos of the size issue. Any suggestions?? Thanks! Dhanya
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: