Java FileOutputStream close() Example

FileOutputStream class close() method example. This example shows you how to use close() method.


Syntax is : public void close() throws IOException
Method closes this file output stream and releases any system resources associated with this stream. This file output stream may no longer be used for writing bytes. If this stream has an associated channel then the channel is closed as well.

Here is the code.
/**
 * @(#) CloseFileOutputStream.java
 * A class representing use of method close() of FileOutputStream 
 class in java.io Package.
 * @Version  05-June-2008
 @author   Rose India Team
 */
import java.io.*;
public class CloseFileOutputStream {
     public static void main(String[] args) {

        try{
            // Create object of FileOutputStream class
            FileOutputStream objFileStream = new FileOutputStream("Mahendra");

        // close() method call.
            objFileStream.close();
            objFileStream.write(65);
        }
        catch Exception e){
      System.out.println("Can't perform write operation on output stream"
      +" because buffer is closed now.");
        }
    }  
}

output of the program.
Can't perform write operation on output stream because buffer is closed now.

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US