tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > Append File

Append File 

The following example shows how to append text to an existing file.

File Name  :  
com/bethecoder/tutorials/io/AppendFileTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

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

public class AppendFileTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    try {
      //Open file writer for appending text
      BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\abc.txt"true));
      writer.newLine();
      writer.write("Hello World2");
      writer.newLine();
      writer.write("Hello World3");
      writer.close();
      System.out.println("Successfully appended to file");
    catch (IOException e) {
      e.printStackTrace();
    }

  }

}
   

It gives the following output,
Successfully appended to file



 
  


  
bl  br