I’m writing information to a file, through a DataOutputStream (RandomAccessFile->FileOutputStream->BufferedOutputStream->DataOutputStream).
I assume that if the buffer used for data output is filled, then the dataoutput stream would automatically flush?
The reason I ask is that I’m writing the data in a for loop, and flushing after the loop (I’m guessing that flushing after every iteration of the loop would destroy the point of using buffers), and when the data gets too big (4MB atm) my file isn’t coming out correctly.
DataOutputStreamdoesn’t have a buffer, so there is nothing to flush. Everything is written within thewrite()/writeXXX()methods. However theBufferedOutputStreamhas a buffer of course, so you certainly need to flush or close to get that data written to the file. You need to close the outermost stream, i.e. in this case theDataOutputStream, not any of the nested streams.You’ll have to post your code.
BufferedOutputStream‘s buffer is 8k bytes by default, nothing to do with 4Mb.