How the .flush() method works ?

Posted on 2007-07-24
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.
Question by:jonathan_otero
    LVL 86

    Expert Comment

    flush simply causes an immediate write to the stream, rather than keeping it in a buffer
    LVL 5

    Accepted Solution

    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.
    LVL 3

    Assisted Solution

    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.
    LVL 86

    Expert Comment

    jonathan_otero, can you tell me why my (correct) answer was ignored? Please see guidelines for site

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now