Writing to a File: If the file does not exist, it is automatically created. : BufferedWriter « File Input Output « Java






Writing to a File: If the file does not exist, it is automatically created.

 

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

public class Main {
  public static void main(String[] argv) throws Exception {

    BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
    out.write("asdf");
    out.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.Appending to a File
6.Write text file
7.Nested creation of FileWriter, BufferedWriter and PrintWriter
8.Create BufferedWriter from FileWriter and write strings to the file