Write byte array to a file using FileOutputStream - Java File Path IO

Java examples for File Path IO:FileOutputStream

Description

Write byte array to a file using FileOutputStream

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
   /*from ww w .  j a v  a 2 s .co m*/
    String strFilePath = "C://Folder//demo.txt";
   
     try
     {
       FileOutputStream fos = new FileOutputStream(strFilePath);
       String strContent = "Write File using Java FileOutputStream 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