Java.io.CharArrayWriter.write() Method


Advertisements


Description

The java.io.BufferedInputStream.write(int c) method writes a character in the form of integer to the writer.

Declaration

Following is the declaration for java.io.CharArrayWriter.write(int c) method −

public void write(int c)

Parameters

c − int representing a character to be written.

Return Value

This method does not return any value.

Exception

NA

Example

The following example shows the usage of java.io.CharArrayWriter.write(int c) method.

package com.tutorialspoint;

import java.io.CharArrayWriter;

public class CharArrayWriterDemo {

   public static void main(String[] args) {      
      int i = 0;
      String str = "";
      CharArrayWriter chw = null;
            
      try {
      
         // create character array writer
         chw = new CharArrayWriter();

         // from integer 65 to 69
         for(i = 65; i<70; i++) {
         
            // write integer to writer
            chw.write(i);
            
            // get the default character set value
            str = chw.toString();
            
            // print the string
            System.out.println(str);
         }
         
      } catch(Exception e) {
         
         // for any error
         e.printStackTrace();
      } finally {
         
         // releases all system resources from writer
         if(chw!=null)
            chw.close();
      }
   }
}

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

A
AB
ABC
ABCD
ABCDE

java_io_chararraywriter.htm

Advertisements