| |
|
| java.lang.Object java.io.OutputStream java.io.FileOutputStream
FileOutputStream | public class FileOutputStream extends OutputStream implements Closeable(Code) | | FileOutputStream is a class whose underlying stream is represented by a file
in the operating system. The bytes that are written to this stream are passed
directly to the underlying operating system equivalent function. Since
overhead may be high in writing to the OS, FileOutputStreams are usually
wrapped with a BufferedOutputStream to reduce the number of times the OS is
called.
BufferedOutputStream buf = new BufferedOutputStream(new FileOutputStream("aFile.txt"));
See Also: FileInputStream |
Constructor Summary | |
public | FileOutputStream(File file) Constructs a new FileOutputStream on the File file . | public | FileOutputStream(File file, boolean append) Constructs a new FileOutputStream on the File file . | public | FileOutputStream(FileDescriptor fd) Constructs a new FileOutputStream on the FileDescriptor fd . | public | FileOutputStream(String filename) Constructs a new FileOutputStream on the file named fileName .
If the file exists, it is written over. | public | FileOutputStream(String filename, boolean append) Constructs a new FileOutputStream on the file named filename .
If the file exists, it is written over. |
Method Summary | |
public void | close() Close the FileOutputStream. | protected void | finalize() Frees any resources allocated to represent this FileOutputStream before
it is garbage collected. | public FileChannel | getChannel() Answers 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 FileOutputStream
within the file. | final public FileDescriptor | getFD() Answers a FileDescriptor which represents the lowest level representation
of a OS stream resource. | public void | write(byte[] buffer) Writes the entire contents of the byte array buffer to
this FileOutputStream. | public void | write(byte[] buffer, int offset, int count) Writes count bytes from the byte array
buffer starting at offset to this
FileOutputStream. | public void | write(int oneByte) Writes the specified byte oneByte to this
FileOutputStream. |
FileOutputStream | public FileOutputStream(String filename) throws FileNotFoundException(Code) | | Constructs a new FileOutputStream on the file named fileName .
If the file exists, it is written over. See the constructor which can
append to the file if so desired. The fileName may be
absolute or relative to the System property "user.dir" .
Parameters: filename - the file on which to stream writes. throws: FileNotFoundException - If the filename cannot be opened for writing. |
FileOutputStream | public FileOutputStream(String filename, boolean append) throws FileNotFoundException(Code) | | Constructs a new FileOutputStream on the file named filename .
If the file exists, it is written over. The parameter append
determines whether or not the file is opened and appended to or just
opened empty. The filename may be absolute or relative to
the System property "user.dir" .
Parameters: filename - the file on which to stream writes. Parameters: append - a boolean indicating whether or not to append to an existingfile. throws: FileNotFoundException - If the filename cannot be opened for writing. |
close | public void close() throws IOException(Code) | | Close the FileOutputStream. This implementation closes the underlying OS
resources allocated to represent this stream.
throws: IOException - If an error occurs attempting to close this FileOutputStream. |
finalize | protected void finalize() throws IOException(Code) | | Frees any resources allocated to represent this FileOutputStream before
it is garbage collected. This method is called from the Java Virtual
Machine.
throws: IOException - If an error occurs attempting to finalize thisFileOutputStream. |
getChannel | public FileChannel getChannel()(Code) | | Answers 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 FileOutputStream
within the file. All changes made to the underlying file descriptor state
via the channel are visible by the output stream and vice versa.
the file channel representation for this FileOutputStream. |
getFD | final public FileDescriptor getFD() throws IOException(Code) | | Answers a FileDescriptor which represents the lowest level representation
of a OS stream resource.
a FileDescriptor representing this FileOutputStream. throws: IOException - If the Stream is already closed and there is noFileDescriptor. |
write | public void write(byte[] buffer) throws IOException(Code) | | Writes the entire contents of the byte array buffer to
this FileOutputStream.
Parameters: buffer - the buffer to be written throws: IOException - If an error occurs attempting to write to thisFileOutputStream. |
write | public void write(byte[] buffer, int offset, int count) throws IOException(Code) | | Writes count bytes from the byte array
buffer starting at offset to this
FileOutputStream.
Parameters: buffer - the buffer to be written Parameters: offset - offset in buffer to get bytes Parameters: count - number of bytes in buffer to write throws: IOException - If an error occurs attempting to write to thisFileOutputStream. throws: IndexOutOfBoundsException - If offset or count are outside of bounds. throws: NullPointerException - If buffer is null . |
write | public void write(int oneByte) throws IOException(Code) | | Writes the specified byte oneByte to this
FileOutputStream. Only the low order byte of oneByte is
written.
Parameters: oneByte - the byte to be written throws: IOException - If an error occurs attempting to write to thisFileOutputStream. |
|
|
|