This documentation is archived and is not being maintained.

OutputStreamWriter Class

Visual Studio 2005

Provides an implementation of the abstract Writer class specific to writing characters to an OutputStream object.

Package: java.io

Assembly: vjslib (in vjslib.dll)


public class java.io.OutputStreamWriter
    extends java.io.Writer

The following example demonstrates the close, flush, getEncoding, and write methods of the OutputStreamWriter class.

// outputstreamwriter_overview.jsl

import java.io.*;

public class Program
{
    public static void main(String[] args)
    {
        try
        {
            // Create a new instance of a OutputStreamWriter object
            // attached to a ByteArrayOutputStream.
            ByteArrayOutputStream out =
                new ByteArrayOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(out);

            // Write to the output stream.
            String s = "Random bytes";
            writer.write(s);
            writer.flush();

            // Display the contents of the ByteArrayOutputStream.
            System.out.println(out.toString());

            // Display the encoding being used.
            System.out.println("encoding: " +
                writer.getEncoding());

            // Close the OutputStreamWriter object.
            writer.close();
        }
        catch (IOException ex)
        {
            System.out.println(ex.toString());
        }
    }
}

/*
Output:
Random bytes
encoding: Cp1252
*/

java.lang.Object

   java.io.Writer

    java.io.OutputStreamWriter

       java.io.FileWriter

Show: