Java BufferedWriter write text to text file

Description

Java BufferedWriter write text to text file

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

public class Main {
  public static void main(String[] args) {
    String destFile = "C:/Main.txt";

    try (BufferedWriter bw = new BufferedWriter(new FileWriter(destFile))) {
      bw.append("demo2s.com");
      bw.newLine();//ww  w . j a v a2s.  c  o  m
      bw.flush();
      System.out.println("saved to "+ (new File(destFile)).getAbsolutePath());
    } catch (Exception e2) {
      e2.printStackTrace();
    }
  }
}



PreviousNext

Related