meaning of out.flush
flush() causes any remaining characters which are waiting in a stream to actually be sent.
The OutputStream has to store the data it's delaying somewhere, and the place where it stores it is called the "buffer". To "flush the buffer" means to actually write out the data in the buffer. OutputStreams will automatically flush themselves every now and then, but there may be situations where you really need them to flush at a particular point in time. To accomplish this, flush() method is used.