    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class java.io.OutputStreamWriter

    java.lang.Object
       |
       +----java.io.Writer
               |
               +----java.io.OutputStreamWriter

public class OutputStreamWriter
extends Writer

An OutputStreamWriter is a bridge from character streams to byte streams: It translates characters into bytes according to a specified character encoding and writes the bytes to an output stream. The encoding that it uses may be specified by name, or the platform's default encoding may be accepted.

Each invocation of one of an OutputStreamWriter's write() methods may cause one or more bytes to be written to the underlying byte-output stream. For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter; for example,

     Writer out
       = new BufferedWriter(new OutputStreamWriter(System.out));

See Also:
  BufferedWriter, OutputStream

##

OutputStreamWriter(OutputStream)
  Create an OutputStreamWriter that uses the default character encoding.
OutputStreamWriter(OutputStream, String)
  Create an OutputStreamWriter that uses the named character encoding.

##

close()
  Close the stream.
flush()
  Flush the stream.
getEncoding()
  Return the name of the encoding being used by this stream.
write(char[], int, int)
  Write a portion of an array of characters.
write(int)
  Write a single character.
write(String, int, int)
  Write a portion of a string.

##

OutputStreamWriter

      public OutputStreamWriter(OutputStream out,
                                String enc) throws UnsupportedEncodingException

  Create an OutputStreamWriter that uses the named character encoding.

  Parameters:
    out - An OutputStream
    enc - Name of the encoding to be used
  Throws: UnsupportedEncodingException
    If the named encoding is not supported

OutputStreamWriter

      public OutputStreamWriter(OutputStream out)

  Create an OutputStreamWriter that uses the default character encoding.

  Parameters:
    out - An OutputStream

##

getEncoding

      public String getEncoding()

  Return the name of the encoding being used by this stream. May return null if the stream has been closed.

write

      public void write(int c) throws IOException

  Write a single character.

  Throws: IOException
    If an I/O error occurs
  Overrides:
    write in class Writer

write

      public void write(char cbuf[],
                        int off,
                        int len) throws IOException

  Write a portion of an array of characters.

  Parameters:
    cbuf - Buffer of characters
    off - Offset from which to start writing characters
    len - Number of characters to write
  Throws: IOException
    If an I/O error occurs
  Overrides:
    write in class Writer

write

      public void write(String str,
                        int off,
                        int len) throws IOException

  Write a portion of a string.

  Parameters:
    str - A String
    off - Offset from which to start writing characters
    len - Number of characters to write
  Throws: IOException
    If an I/O error occurs
  Overrides:
    write in class Writer

flush

      public void flush() throws IOException

  Flush the stream.

  Throws: IOException
    If an I/O error occurs
  Overrides:
    flush in class Writer

close

      public void close() throws IOException

  Close the stream.

  Throws: IOException
    If an I/O error occurs
  Overrides:
    close in class Writer

    All Packages  Class Hierarchy  This Package  Previous  Next  Index