Unable to write into DataOutputStream beyond a specific size - OutOfMemoryError

前端 未结 2 614
孤街浪徒
孤街浪徒 2020-12-18 06:07

I have the following code which produces an OutOfMemory exception:

byte[] buf = new byte[10240];
int len = 0;
DataOutputStream dataOS = new DataOutputStream(         


        
2条回答
  •  太阳男子
    2020-12-18 06:25

    Depending on the implementation of OutputStream, writing may buffer the content in memory, and not actually send it. If you buffer enough content, you will of course run out of memory.

    At some interval, perhaps each time through your loop, you should call OutputStream.flush(). If there is a buffer in use, that will clear it.

提交回复
热议问题