How can I replace text in a file that is too large for a String? I have been using the following to replace text in most of the files I've seen:
File f = new File("test.xml");
String content = FileUtils.readFileToString(f, "UTF-8");
content = content.replaceFirst("some text", "new text");
FileUtils.writeStringToFile(f, content, "UTF-8");
This works well for files that are normal sized. However, some of the files I have been getting are very large (too large to store in a String) and they cause an overflow. How can I replace text in those files?