Export (0) Print
Expand All

BufferedWriter Class

Visual Studio 2005

Provides an implementation of the abstract Writer class that buffers character data to another writer.

Package: java.io

Assembly: vjslib (in vjslib.dll)


public class java.io.BufferedWriter
    extends java.io.Writer

The following example demonstrates the close, flush, newLine, and write methods of the BufferedWriter class.

// bufferedwriter_overview.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.";

            // Print out the first 12 characters.
            bufWriter.write(s, 0, 12);

            // Print a newline character.
            bufWriter.newLine();

            // Print the rest of the string.
            bufWriter.write(s, 12, s.length() - 12);
            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.
*/

java.lang.Object

   java.io.Writer

    java.io.BufferedWriter

Community Additions

ADD
Show:
© 2014 Microsoft