- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序中有两个文件到字符串的进程(一个实际上处理 Assets 文件)。
如果我对同一个文件重复这些过程中的任何一个几次,我会得到 OutOfMemoryErrors。
我怀疑这可能是因为我没有正确关闭流,因此可能导致创建多个流,这可能导致我的应用程序内存不足。
下面是两个进程的代码:
我的 Assets 文件到字符串的过程。
如您所见,我已经准备好关闭流,但我不知道它的格式是否正确。
try
{
myVeryLargeString = IOUtils.toString(getAssets().open(myAssetsFilePath), "UTF-8");
IOUtils.closeQuietly(getAssets().open(myAssetsFilePath));
}
catch (IOException e)
{
e.printStackTrace();
}
catch(OutOfMemoryError e)
{
Log.e(TAG, "Ran out of memory 01");
}
我的文件到字符串过程。
我不知道如何关闭此流(如果根本没有要关闭的流的话)。
myFile01 = new File(myFilePath);
try
{
myVeryLargeString = FileUtils.readFileToString(myFile01, "UTF-8");
}
catch (IOException e)
{
e.printStackTrace();
}
catch(OutOfMemoryError e)
{
Log.e(TAG, "Ran out of memory 02");
}
最佳答案
很难说什么会导致OOME,但关闭应该是这样的
InputStream is = getAssets().open(myAssetsFilePath);
try {
myVeryLargeString = IOUtils.toString(is, "UTF-8");
} finally {
IOUtils.closeQuietly(is);
}
关于java - 如何正确关闭文件到字符串的输入流? (IOUtils FileUtils),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17397189/
我已经实现了一个 REST 服务,用于使用 IOUtils.copy() 下载一个中等大小 (250 Mb) 的 zip 文件,类似于 Most effective way to write file
我有一个Android 4.0/4.1用户上传的崩溃日志,但我无法重现。日志是这样的: java.io.IOException: close failed: EIO (I/O error) libco
复制方法给我这个错误: “IOUtils 类型中的方法 copy(InputStream, OutputStream) 不适用于参数 (FileInputStream, StringWriter, S
我正在尝试将我的Stanford CoreNLP版本升级到最新版本(之前是v3.5.2,尝试升级到v3.6.0)。编译完 v3.6.0 所需的所有新 jar 后,我启动了一个独立的斯坦福 CoreNL
我使用以下代码在我的 android 应用中创建了一个临时文件: public File streamToFile (InputStream in) throws IOException {
用途:IO工具类(将内容写到流中) 使用场景 IO工具类只是辅助流的读写,并不负责关闭流。原因是流可能被多次读写,读写关闭后容易造成问题。 (将内容写到流中) (将内容写到流中) (将内容
我正在使用 Apache IOUtils 下载文件。为了恢复下载,我使用以下代码: IOUtils.copyLarge(input,output,localFileSize,fileLengthOnS
我需要将 pdf 文件编码/解码为 Base64 格式。所以我从磁盘读取文件到String(因为我将来会收到String Base64格式的文件); String pdfString = IOUtil
我是Golang的新手。 我试图了解如何使用ioutil.ReadAll(非HTTP响应)。根据源代码(和文档): // ReadAll reads from r until an error or
这个问题在这里已经有了答案: 404 page not found - Go rendering css file (1 个回答) No such file or directory error in
我有一个 servlet,它使用具有以下逻辑的方法: ServletOutputStream out = response.getOutputStream(); IOU
我在下面的代码行中收到 OOM 错误。有办法解决吗?我尝试增加堆大小但没有用。 FileInputStream inputDoc = new FileInputStream(inputDoc1); b
使用 IOUtils.write 将字符串写入文件 try { IOUtils.write("test", new FileWriter(configFile)); }
我有一个类,它打开 HTTP 服务器并监听端口。回复是一个 http-header 加上一个 json 对象。该类从服务器获取输入流,将其转换为字符串,过滤 http header 并解析 json
我的应用程序中有两个文件到字符串的进程(一个实际上处理 Assets 文件)。 如果我对同一个文件重复这些过程中的任何一个几次,我会得到 OutOfMemoryErrors。 我怀疑这可能是因为我没有
我不是 Java 开发人员,但只需要了解一些 Java 正在做什么。 我有一些代码 IOUtils.copy(InputStream a, Writer b, "ISO-8859-1") 或类似的文字
我注意到似乎没有办法指定复制方法的字节长度。 copyLarge(InputStream input, OutputStream output, long inputOffset, long leng
这是我的情况:我正在使用 IOUtils 复制文件。接下来我要做的是向另一个程序发送一条 JSON 消息,表示“您可以下载副本”。问题是大约 25% 的时间其他程序收到错误消息“收到意外的 EOF 下
我在 android 上编写应用程序,它将 xml 文件发送到 PHP 服务器。这是我的代码: InputStream is = new FileInputStream(file); HttpClie
我尝试压缩超过 100Mb 的大型视频文件。 public static void compress(File input, File output) throws IOException {
我是一名优秀的程序员,十分优秀!