Introduction

The Java.io.Writer class is a abstract class for writing to character streams.

Class declaration

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

public abstract class Writer
   extends Object
      implements Appendable, Closeable, Flushable

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.Writer class −

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

Class constructors

Sr.No.Constructor & Description
1protected Writer()This creates a new character-stream writer whose critical sections will synchronize on the writer itself.
2protected Writer(Object lock)This creates a new character-stream writer whose critical sections will synchronize on the given object.

Class methods

Sr.No.Method & Description
1Writer append(char c)This method appends the specified character to this writer.
2Writer append(CharSequence csq)This method appends the specified character sequence to this writer.
3Writer append(CharSequence csq, int start, int end)This method appends a subsequence of the specified character sequence to this writer.
4abstract void close()This method loses the stream, flushing it first.
5abstract void flush()This method flushes the stream.
6void write(char[] cbuf)This method writes an array of characters.
7abstract void write(char[] cbuf, int off, int len)This method writes a portion of an array of characters.
8void write(int c)This method writes a single character.
9void write(String str)This method writes a string.
10void 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.Object

Comments

Leave a Reply

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