BufferedWriter in Java

The BufferedWriter class provides a buffered character writer class. The BufferedReader class has two constructors. In the first form a buffered character stream uses a default buffer size. In the second, the size of the buffer is passes into the constructor as show below.

Constructor
Meaning
BufferedWriter(Writer wr);
Construct a buffering character output stream
BufferedWriter(Writer wr, int size)
Construct a buffering character output stream along with given buffered size

Consider the following example which opens file1.txt and writes buffering string into the file.

Example:

/**
From bufferedWriter.java
*/

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 *
 * @author JavaHotSpot
 */

public class bufferedWriter
{
  public static void main(String args[])
  {
      try
      {
          FileWriter fw = new FileWriter("C:\\file1.txt");
          BufferedWriter buff = new BufferedWriter(fw);
          buff.write("This is example of BufferedWriter");
          buff.flush();
          System.out.println("Done...!");

      }
      catch(Exception ex)
      {
          System.err.println(ex);
      }
  }
}

Output: