[英]Writing large files using BufferedOutputStream
I am trying read and write large files (larger than 100 MBs) using BufferedInputStream
& BufferedOutputStream
. 我正在尝试使用BufferedInputStream
和BufferedOutputStream
读写大型文件(大于100 MB)。 I am getting Heap Memory issue & OOM exception. 我收到堆内存问题和OOM异常。
The code looks like : 代码如下:
BufferedInputStream buffIn = new BufferedInputStream(iStream);
/** iStream is the InputStream object **/
BufferedOutputStream buffOut=new BufferedOutputStream(new FileOutputStream(file));
byte []arr = new byte [1024 * 1024];
int available = -1;
while((available = buffIn.read(arr)) > 0) {
buffOut.write(arr, 0, available);
}
buffOut.flush();
buffOut.close();
My question is when we use the BufferedOutputStreeam
is it holding the memory till the full file is written out ? 我的问题是,当我们使用BufferedOutputStreeam
,它是否保持内存直到写出完整的文件?
What is the best way to write large files using BufferedOutputStream
? 使用BufferedOutputStream
写入大文件的最佳方法是什么?
there is nothing wrong with the code you have provided. 您提供的代码没有错。 your memory issues must lie elsewhere. 您的内存问题必须位于其他地方。 the buffered streams have a fixed memory usage limit. 缓冲的流具有固定的内存使用限制。
the easiest way to determine what has caused an OOME, of course, is to have the OOME generate a heap dump and then examine that heap dump in a memory profiler. 当然,确定是什么导致了OOME的最简单方法是让OOME生成堆转储,然后在内存事件探查器中检查该堆转储。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.