I just read that
Some buffered output classes support autoflush, specified by an optional constructor argument. When autoflush is enabled, certain key events cause the buffer to be flushed. For example, an autoflush PrintWriter object flushes the buffer on every invocation of println or format.
So if I am keeping the reference of any BufferReader for some time being and it gets flushed , then how all the data will be retained back? Is there some call back mechanism that will automatically flush it and again read the content or will I lose the data and again I need to call for it?
So if I am keeping the reference of any BufferReader for some time being and it gets flushed , then how all the data will be retained back?
I think you mean BufferedWriter. (Neither the Reader or InputStream APIs have a flush() method. Flushing doesn't make any sense on a "source".)
The flushed data is written to the stream's "sink"; i.e. the file or socket or whatever. So if you look in the file (or whatever), the data will be there if the stream has been flushed (successfully).
Is there some call back mechanism that will automatically flush it and again read the content
There is no callback mechanism1. (At least, not in any of the buffered stream classes that the standard class library provides: who knows what a custom class might do ...)
Data is flushed automatically when certain things happen. For example, when the application calls println ... for a PrintWriter.
... or will I lose the data and again I need to call for it?
This doesn't make sense, either grammatically or semantically. I don't know what you are trying to ask.
Perhaps you don't understand what flushing does. Flushing simply means pushing the data out of the buffers and out to wherever the stream sends its data. An explicit flush() call or an automatic flush just means "write it NOW".
1 - Incidentally, BufferedWriter doesn't have a finalize() method either. This means that if one of these objects becomes unreachable while it still has output buffered, that output will never be written.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With