Why not store the contents of the text file back into the arrays first? You could then loop through the array and perform a better search/replace.

Don't ask me for the code, as I don't work with Java and am now getting poor at writing code that's syntactically correct. Thank God I have MS with me!

.