Nested creation of FileWriter, BufferedWriter and PrintWriter : BufferedWriter « File Input Output « Java






Nested creation of FileWriter, BufferedWriter and PrintWriter

 

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

public class Main {
  public static void main(String[] argv) throws Exception {
    FileWriter file = new FileWriter("a.html");
    BufferedWriter buffer = new BufferedWriter(file);
    PrintWriter out = new PrintWriter(buffer);
    out.println("<html>\n\t<body>");
    out.println("\t</body>\n</html>");
    out.close();
    buffer.close();
    file.close();
  }
}

   
  








Related examples in the same category

1.new BufferedWriter(new OutputStreamWriter(System.out))
2.Read Input From User and Write to File
3.Write to file using a BufferedWriter
4.Use a BufferedReader and a BufferedWriter to copy a text file, inverting the case of letters in the process
5.Writing to a File: If the file does not exist, it is automatically created.
6.Appending to a File
7.Write text file
8.Create BufferedWriter from FileWriter and write strings to the file