All for Joomla All for Webmasters

CharArrayWriter class

The CharArrayWriter class can be used to write data to multiple files. This class implements the Appendable interface. Its buffer automatically grows when data is written in this stream. Calling the close() method on this object has no effect.

Example of CharArrayWriter class:

In this example, we are writing a common data to 4 files a.txt, b.txt, c.txt and d.txt.

  1. import java.io.*;
  2. class Simple{
  3.  public static void main(String args[])throws Exception{
  4.   CharArrayWriter out=new CharArrayWriter();
  5.   out.write(“my name is”);
  6.   FileWriter f1=new FileWriter(“a.txt”);
  7.   FileWriter f2=new FileWriter(“b.txt”);
  8.   FileWriter f3=new FileWriter(“c.txt”);
  9.   FileWriter f4=new FileWriter(“d.txt”);
  10.   out.writeTo(f1);
  11.   out.writeTo(f2);
  12.   out.writeTo(f3);
  13.   out.writeTo(f4);
  14.   f1.close();
  15.   f2.close();
  16.   f3.close();
  17.   f4.close();
  18.  }
  19. }
PinIt
submit to reddit

Leave a Reply

Top