Because, you can see from the error message, the JVM does a arrayCopy when it expands the StringBuilder. If the StirngBuilder needs to be expanded whenever you append a char, then JVM will do this array copy again and again which consumes a lot of memory. I think you need to change your way of reading with buffering. try using readLine(byte[] b,int off,int len) method of ServletInputStream.