java - 字符串缓冲区 - OutOfMemoryError

标签 java stringbuffer

我有字符串缓冲区变量,它保存我从文件读取的输入。在某些情况下,我收到的输入文件很大。在这些情况下,我会收到 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/

相关文章:

java - SpringBoot反序列化无默认构造函数

java - 连接字符串的最有效方法

java - String的子串函数与StringBuffer的子串函数

c++ - 使用相同的流对象写入文件流或字符串流

java - 无法重置 JavaFX 应用程序中的 StringBuffer

java - 需要删除字符串中多余的方括号

java - 随机5个不同的数字

java - 将参数传递到函数接口(interface)的 ArgumentCaptor 中

java - 如何捕获字母并显示错误并且仅显示整数?

java - 在不使用脚本引擎的情况下评估 kotlin 中的字符串表达式