Java.io.Writer.append() Method

Advertisements


Description

The java.io.Writer.append(char c) method appends the specified character to this writer.

Declaration

Following is the declaration for java.io.Writer.append() method

public Writer append(char c)

Parameters

  • c -- The 16-bit character to append

Return Value

This method returns this writer

Exception

  • IOException -- If an I/O error occurs

Example

The following example shows the usage of java.io.Writer.append() method.

package com.tutorialspoint;

import java.io.*;

public class WriterDemo {

   public static void main(String[] args) {
      char c = 'A';

      // create a new writer
      Writer writer = new PrintWriter(System.out);

      try {
         // append a char
         writer.append('c');

         // append a new char
         writer.append(c);

         // flush the writer to see the result
         writer.flush();

      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

Let us compile and run the above program, this will produce the following result:

cA



Advertisements
Advertisements