Sunday, November 27, 2011

Create FileOutputStream object from String file path

    package org.best.example;
    /*
      Create FileOutputStream object from String file path
      This example shows how to create FileOutputStream object from String containing
      file path.
    */
    
    import java.io.*;
    
    public class CreateFileOutputStreamObjectFromString {
    
      public static void main(String[] args) {
      
        String strFilePath = "C://FileIO//demo.txt";
      
        /*
         * To create FileOutputStream object from String use,
         * FileOutputStream(String filePath) constructor.
         */
      
         try
         {
           FileOutputStream fos = new FileOutputStream(strFilePath);
         }
         catch(FileNotFoundException ex)
         {
           System.out.println("Exception : " + ex);
         }
      }
    }

No comments: