我有字符串缓冲区变量,它保存我从文件读取的输入。在某些情况下,我收到的输入文件很大。在这些情况下,我会收到 OutOfMemoryError 错误。
这是我的代码:
StringBuffer response = new StringBuffer("");
BufferedReader in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null)
response.append(inputLine);
in.close();
请帮我解决这个问题。
最佳答案
以 block 的形式读取输入,或者将 JVM 中的 -Xmx
参数(最大内存大小)更改为更大的大小。
关于java - 字符串缓冲区 - OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16080287/