Create BufferedWriter from FileWriter : BufferedWriter « File « Java Tutorial






import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;

public class MainClass {
  public static void main(String[] args) throws IOException {
    try {
      BufferedReader in4 = new BufferedReader(new StringReader("asdf"));
      PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out")));
      int lineCount = 1;
      String s = null;
      while((s = in4.readLine()) != null )
        out1.println(lineCount++ + ": " + s);
      out1.close();
    } catch(EOFException e) {
      System.err.println("End of stream");
    }

  }
}








11.36.BufferedWriter
11.36.1.BufferedWriter
11.36.2.Create BufferedWriter from FileWriter
11.36.3.Read Input From User and Write to File
11.36.4.Write to file using a BufferedWriter
11.36.5.Use a BufferedReader and a BufferedWriter to copy a text file, inverting the case of letters in the process
11.36.6.Writing to a File: If the file does not exist, it is automatically created.
11.36.7.Appending to a File
11.36.8.Nested creation of FileWriter, BufferedWriter and PrintWriter