Sample Programs

Sample java program to append data to end of text file

 package org.jusfortechies.example; 

 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 
 public class AppendTextToEndOfFile {

   public static void main(String[] args) {

      File file = new File("C:\\sample.txt");

      try {
         FileWriter writer = new FileWriter(file, true);

         writer.write("This is sample text to test appending text to end of file. ");

         writer.flush();
         writer.close();

      } catch (IOException e) {
         System.err.println("Unable to append text to file : " + e);
      }
   }

 }




blog comments powered by Disqus