Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Can someone explain what out.flush() does?
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.


Report this thread to moderator Post Follow-up to this message
Old Post
computerkaitee@yahoo.com
02-17-06 12:04 AM


Re: Can someone explain what out.flush() does?
<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


Report this thread to moderator Post Follow-up to this message
Old Post
Oliver Wong
02-17-06 12:04 AM


Re: Can someone explain what out.flush() does?

computerkaitee@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


Report this thread to moderator Post Follow-up to this message
Old Post
Eric Sosman
02-17-06 12:04 AM


Re: Can someone explain what out.flush() does?
Thanks, this is what I needed.
-Kaitee


Report this thread to moderator Post Follow-up to this message
Old Post
computerkaitee@yahoo.com
02-17-06 12:04 AM


Re: Can someone explain what out.flush() does?
On 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Roedy Green
02-17-06 08:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:46 PM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.