FileWriter : FileWriter « File « Java Tutorial





  1. FileWriter provides a convenient way of writing characters to a file.
  2. FileWriter uses your computer's default character encoding.
public FileWriter (File file)
public FileWriter (File file, boolean append)

public FileWriter (String path)
public FileWriter (String path, boolean append)
public FileWriter (FileDescriptor fileDescriptor)

For example, you can construct a Writer that writes to a file easily using FileWriter:

import java.io.FileWriter;
import java.io.IOException;

public class MainClass {
  public static void main(String[] a) {
    FileWriter writer;
    try {
      writer = new FileWriter("myFile.txt");
      char c = 'A';
      writer.write(c);
      writer.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

  }
}










11.33.FileWriter
11.33.1.FileWriter
11.33.2.Use FileWriter to write an array of strings to a file.
11.33.3.Append or add some contents to the file
11.33.4.Wrap FileWriter with BufferedWriter