Skip to Content

Create FileOutputStream object from String file path

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