Write text file : BufferedWriter « File Input Output « Java

Write text file


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

public class Main {
  public static void main(String[] args) throws Exception {
    Writer writer = null;

    String text = "This is a text file";

    File file = new File("write.txt");
    writer = new BufferedWriter(new FileWriter(file));



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.Nested creation of FileWriter, BufferedWriter and PrintWriter
8.Create BufferedWriter from FileWriter and write strings to the file