Code Comments
Programming Forum and web based access to our favorite programming groups.Can someone explain what out.flush() does? Or if you could direct me to some documentation on it. I can't seem to find it anywhere.
Post Follow-up to this message<computerkaitee@yahoo.com> wrote in message news:1140122341.444997.241450@g47g2000cwa.googlegroups.com... > Can someone explain what out.flush() does? Or if you could direct me > to some documentation on it. I can't seem to find it anywhere. "out" is some object, and the "flush()" method is being called on that object. To be pedantic, out could theoretically be any object, as long as that object implements the "flush" method, and the "flush" method could do anything. To be more helpful though, I'm guessing "out" here refers to "System.out" or some sort of OutputStream. The API documentation for OutputStream is at http://java.sun.com/j2se/1.5.0/docs...tputStream.html and the documentation for its flush() method says: <quote> Flushes this output stream and forces any buffered output bytes to be written out. </quote> What this means is that when you tell an OutputStream to write something, it might not actually write that data right away. There are several reasons why it might delay writing. One might be that it's expensive to set-up the environment in such a way so that writing becomes possible, so the OutputStream will wait until it has a big chunk of data before actually doing the writing. This is like when you go grocery shopping. You don't wanna leave your house, buy eggs, come back, find out you're missing milk, leave your house, buy milk, come back, find out you're missing bread, leave your house, etc. You'd rather get a shopping list established first, so that you can buy everything in one trip. 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, you call the flush() method. - Oliver
Post Follow-up to this messagecomputerkaitee@yahoo.com wrote On 02/16/06 15:39,: > Can someone explain what out.flush() does? Or if you could direct me > to some documentation on it. I can't seem to find it anywhere. What is `out'? If you're referring to `System.out', you should be able to find what you need in the Javadoc: - Look up the documentation for the System class, and you'll learn that `out' is a PrintStream. - Hyperlink to the PrintStream class, and you'll find a description of its flush() method. The description is brief, but mentions that PrintStream's flush() is an override of FilterOutputStream's flush(). Overriding methods are usually specializations or refinements of the overridden methods, so it makes sense to - ... hyperlink to the FilterOutputStream class, and you'll learn that its flush() method is also an override of the still higher OutputStream class. So - ... hyperlink to OutputStream, and you'll come to a more comprehensive description of what flush() does. If things still don't make sense after you've read this stuff, come back and ask again. But take a hint: If you're going to get anywhere with Java, you'll need to develop some skill in how to use the Javadoc. -- Eric.Sosman@sun.com
Post Follow-up to this messageThanks, this is what I needed. -Kaitee
Post Follow-up to this messageOn 16 Feb 2006 12:39:01 -0800, computerkaitee@yahoo.com wrote, quoted or indirectly quoted someone who said : >Can someone explain what out.flush() does? Or if you could direct me >to some documentation on it. I can't seem to find it anywhere. see http://mindprod.com/jgloss/flush.html -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.