java.lang.Object | ||
↳ | java.io.OutputStream | |
↳ | java.io.FileOutputStream |
Known Direct Subclasses |
Known Indirect Subclasses |
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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new FileOutputStream on the File
file . | |||||||||||
Constructs a new FileOutputStream on the File
file . | |||||||||||
Constructs a new FileOutputStream on the FileDescriptor
fd . | |||||||||||
Constructs a new FileOutputStream on the file named
filename . | |||||||||||
Constructs a new FileOutputStream on the file named
filename . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes this stream.
| |||||||||||
Returns the FileChannel equivalent to this output stream.
| |||||||||||
Returns a FileDescriptor which represents the lowest level representation
of an operating system stream resource.
| |||||||||||
Writes
count bytes from the byte array buffer starting at
offset to this stream. | |||||||||||
Writes the entire contents of the byte array
buffer to this
stream. | |||||||||||
Writes the specified byte
oneByte to this stream. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Frees any resources allocated for this stream before it is garbage
collected.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.io.OutputStream
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.io.Closeable
| |||||||||||
From interface java.io.Flushable
|
Constructs a new FileOutputStream on the File file
. If the file
exists, it is overwritten.
file | the file to which this stream writes. |
---|
FileNotFoundException | if file cannot be opened for writing. |
---|---|
SecurityException | if a SecurityManager is installed and it denies the
write request. |
Constructs a new FileOutputStream on the File file
. The
parameter append
determines whether or not the file is opened and
appended to or just opened and overwritten.
file | the file to which this stream writes. |
---|---|
append | indicates whether or not to append to an existing file. |
FileNotFoundException | if the file cannot be opened for writing. |
---|---|
SecurityException | if a SecurityManager is installed and it denies the
write request. |
Constructs a new FileOutputStream on the FileDescriptor fd
. The
file must already be open, therefore no FileNotFoundException
will be thrown.
fd | the FileDescriptor to which this stream writes. |
---|
NullPointerException | if fd is null . |
---|---|
SecurityException | if a SecurityManager is installed and it denies the
write request. |
Constructs a new FileOutputStream on the file named filename
. If
the file exists, it is overwritten. The filename
may be absolute
or relative to the system property "user.dir"
.
filename | the name of the file to which this stream writes. |
---|
FileNotFoundException | if the file cannot be opened for writing. |
---|---|
SecurityException | if a SecurityManager is installed and it denies the
write request.
|
Constructs a new FileOutputStream on the file named filename
.
The parameter append
determines whether or not the file is opened
and appended to or just opened and overwritten. The filename
may
be absolute or relative to the system property "user.dir"
.
filename | the name of the file to which this stream writes. |
---|---|
append | indicates whether or not to append to an existing file. |
FileNotFoundException | if the file cannot be opened for writing. |
---|---|
SecurityException | if a SecurityManager is installed and it denies the
write request.
|
Closes this stream. This implementation closes the underlying operating system resources allocated to represent this stream.
IOException | if an error occurs attempting to close this stream. |
---|
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.
Returns a FileDescriptor which represents the lowest level representation of an operating system stream resource.
IOException | if an error occurs attempting to get the FileDescriptor of this stream. |
---|
Writes count
bytes from the byte array buffer
starting at
offset
to this stream.
buffer | the buffer to write to this stream. |
---|---|
offset | the index of the first byte in buffer to write. |
count | the number of bytes from buffer to write. |
IndexOutOfBoundsException | if count < 0 or offset < 0 , or if
count + offset is greater than the length of
buffer . |
---|---|
IOException | if this stream is closed or an error occurs attempting to write to this stream. |
NullPointerException | if buffer is null .
|
Writes the entire contents of the byte array buffer
to this
stream.
buffer | the buffer to be written to the file. |
---|
IOException | if this stream is closed or an error occurs attempting to write to this stream. |
---|
Writes the specified byte oneByte
to this stream. Only the low
order byte of the integer oneByte
is written.
oneByte | the byte to be written. |
---|
IOException | if this stream is closed an error occurs attempting to write to this stream. |
---|
Frees any resources allocated for this stream before it is garbage collected. This method is called from the Java Virtual Machine.
IOException | if an error occurs attempting to finalize this stream. |
---|