OutOfMemoryError « StringBuffer « Java Data Type Q&A





1. String, StringBuffer & OutOfMemoryError    coderanch.com

Hi All, I have the code which read big UTF strings public static String readUTFSafely(DataInputStream inputStream) throws IOException { int blocksAmount = inputStream.readInt(); StringBuffer buffer = new StringBuffer(blocksAmount * 21845); for (int i = 0; i < blocksAmount; ++i) { buffer.append(inputStream.readUTF()); } return buffer.toString(); } In some cases this code throws OutOfMemoryError. As I understand, it happens because StringBuffer cannot allocate ...

2. String, StringBuffer & OutOfMemoryError    forums.oracle.com