while coding with the OutputStreamWriter object that writes into a array of bytes, I found out that the array was not being filled with elements until I implemented the method flush(). so basically flush() method "is" required to be executed on this OutputStreamWriter object in order for the elements to be written into the array. what exactly is this flush() and what does it do ?
Basically, you invoke flush to commit everything that you wrote to a buffered stream. Sometimes when stream are buffered, what you write is not written directly onto the stream for efficiency purposes. Be sure to flush the stream once you're done with it in order to get the byte written to it, otherwise the result may be undeterminated.
From the API OutputStream.flush Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination. To be sure the bytes written to the stream object were really written to the "media" that represents, instead of being hold in a buffer, call flush.