java.lang.Object | ||
↳ | java.io.OutputStream | |
↳ | java.io.FileOutputStream |
Known Direct Subclasses |
Known Indirect Subclasses |
An output stream that writes bytes to a file. If the output file exists, it can be replaced or appended to. If it does not exist, a new file will be created.
File file = ...
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
...
finally {
if (out != null) {
out.close();
}
}
}
This stream is not buffered. Most callers should wrap
this stream with a BufferedOutputStream
.
Use FileWriter
to write characters, as opposed to bytes, to a file.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
FileOutputStream that writes to file . | |||||||||||
Constructs a new
FileOutputStream that writes to file ,
creating it if necessary. | |||||||||||
Constructs a new
FileOutputStream that writes to fd . | |||||||||||
Equivalent to
new FileOutputStream(new File(path), false) . | |||||||||||
Equivalent to
new FileOutputStream(new File(path), append) . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes this stream.
| |||||||||||
Returns a write-only
FileChannel that shares its position with
this stream. | |||||||||||
Returns the underlying file descriptor.
| |||||||||||
Writes
count bytes from the byte array buffer starting at
position offset to this stream. | |||||||||||
Writes the entire contents of the byte array
buffer to this
stream. | |||||||||||
Writes a single byte 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
that writes to file
.
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
that writes to file
,
creating it if necessary. If append
is true and the file already
exists, it will be appended to. Otherwise a new file will be created.
file | the file to which this stream writes. |
---|---|
append | true 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
that writes to fd
.
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. |
Equivalent to new FileOutputStream(new File(path), false)
.
FileNotFoundException |
---|
Equivalent to new FileOutputStream(new File(path), append)
.
FileNotFoundException |
---|
Closes this stream. Implementations of this method should free any resources used by the stream. This implementation does nothing.
IOException |
---|
Returns a write-only FileChannel
that shares its position with
this stream.
Returns the underlying file descriptor.
IOException |
---|
Writes count
bytes from the byte array buffer
starting at
position offset
to this stream.
buffer | the buffer to be written. |
---|---|
offset | the start position in buffer from where to get bytes. |
byteCount | the number of bytes from buffer to write to this
stream. |
IOException |
---|
Writes the entire contents of the byte array buffer
to this
stream.
buffer | the buffer to be written. |
---|
IOException |
---|
Writes a single byte to this stream. Only the least significant byte of
the integer oneByte
is written to the stream.
oneByte | the byte to be written. |
---|
IOException |
---|
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. |
---|