OutputStreamWriter 

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 −

public class OutputStreamWriter
   extends Writer

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

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
1OutputStreamWriter(OutputStream out)This creates an OutputStreamWriter that uses the default character encoding.
2OutputStreamWriter(OutputStream out, Charset cs)This creates an OutputStreamWriter that uses the given charset.
3OutputStreamWriter(OutputStream out, CharsetEncoder enc)This creates an OutputStreamWriter that uses the given charset encoder.
4OutputStreamWriter(OutputStream out, String charsetName)This creates an OutputStreamWriter that uses the named charset.

Class methods

Sr.No.Method & Description
1void close()This method closes the stream, flushing it first.
2void flush()This method flushes the stream.
3String getEncoding()This method returns the name of the character encoding being used by this stream.
4void write(char[] cbuf, int off, int len)This method writes a portion of an array of characters.
5void write(int c)This method writes a single character.
6void 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

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *