Skip to Content

Create FileOutputStream object from File object

  1. /*
  2.   Create FileOutputStream object from File object
  3.   This example shows how to skip createFileOutputStream object from File object.
  4. */
  5.  
  6. import java.io.*;
  7.  
  8. public class CreateFileOutputStreamObjectFromFile {
  9.  
  10.   public static void main(String[] args) {
  11.    
  12.     File file = new File("C://FileIO//demo.txt");
  13.    
  14.     /*
  15.      * To create FileOutputStream object from File object use,
  16.      * FileOutputStream(File file) constructor.
  17.      */
  18.    
  19.      try
  20.      {
  21.       FileOutputStream fos = new FileOutputStream(file);
  22.      }
  23.      catch(FileNotFoundException ex)
  24.      {
  25.       System.out.println("Exception : " + ex);
  26.      }
  27.   }
  28. }