Append output to file using FileOutputStream - Java File Path IO

Java examples for File Path IO:FileOutputStream

Description

Append output to file using FileOutputStream

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
   /*ww  w  .j a va  2s.c o  m*/
    String strFilePath = "C://Folder//demo.txt";
   
     try{
       FileOutputStream fos = new FileOutputStream(strFilePath, true);
       String strContent = "Append output to a file example";
       fos.write(strContent.getBytes());
       fos.close();
     }
     catch(FileNotFoundException ex)
     {
      System.out.println("FileNotFoundException : " + ex);
     }
     catch(IOException ioe)
     {
      System.out.println("IOException : " + ioe);
     }
   
  }
}

Related Tutorials