Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

BufferedWriter.flush Method

Visual Studio 2005

Flushes the contents of the internal buffer to the underlying writer. The underlying writer is also flushed.

Package: java.io

Assembly: vjslib (in vjslib.dll)


public void flush() throws java.io.IOException;

The following example demonstrates how to flush the internal buffer of a BufferedWriter object.

// bufferedwriter_flush.jsl

import java.io.*;

public class Program
{
    public static void main(String[] args)
    {
        try
        {
            // Create a new instance of a BufferedWriter object using
            // a StringWriter.
            StringWriter stringWriter = new StringWriter();
            BufferedWriter bufWriter = new BufferedWriter(stringWriter);

            // Write to the underlying StringWriter.
            String s = "This is the string being written.";
            bufWriter.write(s);
            bufWriter.flush();
            System.out.println(stringWriter.getBuffer());

            // Close the BufferedWriter object and the underlying
            // StringWriter object.
            stringWriter.close();
            bufWriter.close();
        }
        catch (IOException ex)
        {
            System.out.println(ex.toString());
        }
    }
}

/*
Output:
This is the string being written.
*/

Community Additions

ADD
Show:
© 2015 Microsoft