jcontrol.io
Class FileOutputStream

java.lang.Object
  extended by jcontrol.io.FileOutputStream
All Implemented Interfaces:
BasicOutputStream

public class FileOutputStream
extends Object
implements BasicOutputStream

A file output stream is an output stream for writing data to a File or to a FileDescriptor. Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileOutputStream (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.

FileOutputStream is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using FileWriter.

Since:
JDK1.0
See Also:
File, FileDescriptor, FileInputStream

Constructor Summary
FileOutputStream(File file)
          Creates a file output stream to write to the file represented by the specified File object.
FileOutputStream(File file, boolean append)
          Creates a file output stream to write to the file represented by the specified File object.
FileOutputStream(String name)
          Creates an output file stream to write to the file with the specified name.
FileOutputStream(String name, boolean append)
          Creates an output file stream to write to the file with the specified name.
 
Method Summary
 void close()
          Closes this file output stream and releases any system resources associated with this stream.
protected  void finalize()
          Free internal data structures used by this file object.
 void flush()
          flush the current stream.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this file output stream.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this file output stream.
 void write(int b)
          Writes the specified byte to this file output stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notifyAll, toString, wait
 

Constructor Detail

FileOutputStream

public FileOutputStream(String name,
                        boolean append)
                 throws FileNotFoundException,
                        IOException
Creates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

Parameters:
name - the system-dependent filename
append - true for appending data at end of file, false for overwrite file
Throws:
FileNotFoundException - if the file not exists or is not a regular file
IOException - can not be created, or cannot be opened for any other reason

FileOutputStream

public FileOutputStream(String name)
                 throws FileNotFoundException,
                        IOException
Creates an output file stream to write to the file with the specified name. A new FileDescriptor object is created to represent this file connection.

Parameters:
name - the system-dependent filename
Throws:
FileNotFoundException - if the file not exists or is not a regular file
IOException - can not be created, or cannot be opened for any other reason

FileOutputStream

public FileOutputStream(File file,
                        boolean append)
                 throws FileNotFoundException,
                        IOException
Creates a file output stream to write to the file represented by the specified File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

Parameters:
file - the file to be opened for writing.
append - true for appending data at end of file, false for overwrite file
Throws:
FileNotFoundException - if the file not exists or is not a regular file
IOException - can not be created, or cannot be opened for any other reason

FileOutputStream

public FileOutputStream(File file)
                 throws FileNotFoundException,
                        IOException
Creates a file output stream to write to the file represented by the specified File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

Parameters:
file - the file to be opened for writing.
Throws:
FileNotFoundException - if the file not exists or is not a regular file
IOException - can not be created, or cannot be opened for any other reason
Method Detail

write

public void write(int b)
           throws IOException
Writes the specified byte to this file output stream. Implements the write method of OutputStream.

Specified by:
write in interface BasicOutputStream
Parameters:
b - the byte to be written.
Throws:
IOException - if an I/O error occurs.

write

public void write(byte[] b)
           throws IOException
Writes b.length bytes from the specified byte array to this file output stream.

Specified by:
write in interface BasicOutputStream
Parameters:
b - the data.
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.write(byte[], int, int)

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this file output stream.

Specified by:
write in interface BasicOutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs.

flush

public void flush()
           throws IOException
flush the current stream.

NOTE: Not Supported

Specified by:
flush in interface BasicOutputStream
Throws:
IOException

close

public void close()
           throws IOException
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.

Specified by:
close in interface BasicOutputStream
Throws:
IOException - if an I/O error occurs.

finalize

protected void finalize()
Free internal data structures used by this file object.