Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How the .flush() method works ?

Posted on 2007-07-24
4
Medium Priority
?
208 Views
Last Modified: 2013-11-24
Can comeone give me a good explanation about how the .flush() method works ?
If there is possible some example ?
I'm using the J2ME platform to do my application.
0
Comment
Question by:jonathan_otero
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 19560021
flush simply causes an immediate write to the stream, rather than keeping it in a buffer
0
 
LVL 5

Accepted Solution

by:
mkatmonkey earned 750 total points
ID: 19560093
The function is well named. If you think of your buffer as a toilet, your data is the water, flush will cause your data to flow into some sort of pipe. Several buffers are auto-flushing. They flush when the buffer reaches a certain level (Aka "water mark"), or after a some time. Other buffers may flush whenever you insert a special character ie a carriage return. When you call flush, any data in your buffer will be sent down to wherever you connected it to.

In general, you shouldn't have to call flush yourself.
0
 
LVL 3

Assisted Solution

by:asood314
asood314 earned 750 total points
ID: 19560176
The flush method empties a buffer by writing all of its contents to the appropriate location.  When you're doing some type of I/O operation using a buffer, you can't be sure that everything's actually been written until you close the file because it might be waiting in the buffer.  The purpose of the flush() method is just to make sure everything in the buffer has been written in case the program crashes.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19564316
jonathan_otero, can you tell me why my (correct) answer was ignored? Please see guidelines for site
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
A solution for Fortify Path Manipulation.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question