English 中文(简体)
Java.io package classes

Java.io package extras

Java.io package Useful Resources

Selected Reading

Java.io - OutputStreamWriter
  • 时间:2024-12-22

Java.io.OutputStreamWriter Class


Previous Page Next Page  

Introduction

The Java.io.OutputStreamWriter class is a bridge from character streams to byte streams. Characters written to it are encoded into bytes using a specified charset.

Class declaration

Following is the declaration for Java.io.OutputStreamWriter class −

pubpc class OutputStreamWriter
   extends Writer

Field

Following are the fields for Java.io.OutputStreamWriter class −

    protected Object lock − This is the object used to synchronize operations on this stream.

Class constructors

Sr.No. Constructor & Description
1

OutputStreamWriter(OutputStream out)

This creates an OutputStreamWriter that uses the default character encoding.

2

OutputStreamWriter(OutputStream out, Charset cs)

This creates an OutputStreamWriter that uses the given charset.

3

OutputStreamWriter(OutputStream out, CharsetEncoder enc)

This creates an OutputStreamWriter that uses the given charset encoder.

4

OutputStreamWriter(OutputStream out, String charsetName)

This creates an OutputStreamWriter that uses the named charset.

Class methods

Sr.No. Method & Description
1 void close()

This method closes the stream, flushing it first.

2 void flush()

This method flushes the stream.

3 String getEncoding()

This method returns the name of the character encoding being used by this stream.

4 void write(char[] cbuf, int off, int len)

This method writes a portion of an array of characters.

5 void write(int c)

This method writes a single character.

6 void write(String str, int off, int len)

This method writes a portion of a string.

Methods inherited

This class inherits methods from the following classes −

    Java.io.Writer

    Java.io.Object

Advertisements