Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » io » [javadoc | source]
java.io
public class: FileOutputStream [javadoc | source]
java.lang.Object
   java.io.OutputStream
      java.io.FileOutputStream

All Implemented Interfaces:
    Closeable, Flushable

Direct Known Subclasses:
    SocketOutputStream

A specialized OutputStream that writes to a file in the file system. All write requests made by calling methods in this class are directly forwarded to the equivalent function of the underlying operating system. Since this may induce some performance penalty, in particular if many small write requests are made, a FileOutputStream is often wrapped by a BufferedOutputStream.
Field Summary
 FileDescriptor fd    The FileDescriptor representing this FileOutputStream. 
 boolean innerFD     
Constructor:
 public FileOutputStream(File file) throws FileNotFoundException 
    Constructs a new FileOutputStream on the File {@code file}. If the file exists, it is overwritten.
    Parameters:
    file - the file to which this stream writes.
    Throws:
    FileNotFoundException - if {@code file} cannot be opened for writing.
    SecurityException - if a {@code SecurityManager} is installed and it denies the write request.
    Also see:
    java.lang.SecurityManager#checkWrite(FileDescriptor)
 public FileOutputStream(FileDescriptor fd) 
    Constructs a new FileOutputStream on the FileDescriptor {@code fd}. The file must already be open, therefore no {@code FileNotFoundException} will be thrown.
    Parameters:
    fd - the FileDescriptor to which this stream writes.
    Throws:
    NullPointerException - if {@code fd} is {@code null}.
    SecurityException - if a {@code SecurityManager} is installed and it denies the write request.
    Also see:
    java.lang.SecurityManager#checkWrite(FileDescriptor)
 public FileOutputStream(String filename) throws FileNotFoundException 
    Constructs a new FileOutputStream on the file named {@code filename}. If the file exists, it is overwritten. The {@code filename} may be absolute or relative to the system property {@code "user.dir"}.
    Parameters:
    filename - the name of the file to which this stream writes.
    Throws:
    FileNotFoundException - if the file cannot be opened for writing.
    SecurityException - if a {@code SecurityManager} is installed and it denies the write request.
 public FileOutputStream(File file,
    boolean append) throws FileNotFoundException 
    Constructs a new FileOutputStream on the File {@code file}. The parameter {@code append} determines whether or not the file is opened and appended to or just opened and overwritten.
    Parameters:
    file - the file to which this stream writes.
    append - indicates whether or not to append to an existing file.
    Throws:
    FileNotFoundException - if the {@code file} cannot be opened for writing.
    SecurityException - if a {@code SecurityManager} is installed and it denies the write request.
    Also see:
    java.lang.SecurityManager#checkWrite(FileDescriptor)
    java.lang.SecurityManager#checkWrite(String)
 public FileOutputStream(String filename,
    boolean append) throws FileNotFoundException 
    Constructs a new FileOutputStream on the file named {@code filename}. The parameter {@code append} determines whether or not the file is opened and appended to or just opened and overwritten. The {@code filename} may be absolute or relative to the system property {@code "user.dir"}.
    Parameters:
    filename - the name of the file to which this stream writes.
    append - indicates whether or not to append to an existing file.
    Throws:
    FileNotFoundException - if the file cannot be opened for writing.
    SecurityException - if a {@code SecurityManager} is installed and it denies the write request.
Method from java.io.FileOutputStream Summary:
close,   finalize,   getChannel,   getFD,   write,   write,   write
Methods from java.io.OutputStream:
checkError,   close,   flush,   write,   write,   write
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.FileOutputStream Detail:
 public  void close() throws IOException 
    Closes this stream. This implementation closes the underlying operating system resources allocated to represent this stream.
 protected  void finalize() throws IOException 
    Frees any resources allocated for this stream before it is garbage collected. This method is called from the Java Virtual Machine.
 public FileChannel getChannel() 
    Returns the FileChannel equivalent to this output stream.

    The file channel is write-only and has an initial position within the file that is the same as the current position of this stream within the file. All changes made to the underlying file descriptor state via the channel are visible by the output stream and vice versa.

 public final FileDescriptor getFD() throws IOException 
    Returns a FileDescriptor which represents the lowest level representation of an operating system stream resource.
 public  void write(byte[] buffer) throws IOException 
    Writes the entire contents of the byte array {@code buffer} to this stream.
 public  void write(int oneByte) throws IOException 
    Writes the specified byte {@code oneByte} to this stream. Only the low order byte of the integer {@code oneByte} is written.
 public  void write(byte[] buffer,
    int offset,
    int count) throws IOException 
    Writes {@code count} bytes from the byte array {@code buffer} starting at {@code offset} to this stream.