public class FileOutputStream
extends java.io.OutputStream
implements java.io.Closeable
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.
BufferedOutputStream
,
FileInputStream
Constructor and Description |
---|
FileOutputStream(File file)
Constructs a new
FileOutputStream that writes to file . |
FileOutputStream(File file,
boolean append)
Constructs a new
FileOutputStream that writes to file . |
FileOutputStream(FileDescriptor fd)
Constructs a new
FileOutputStream that writes to fd . |
FileOutputStream(java.lang.String path)
Constructs a new
FileOutputStream that writes to path . |
FileOutputStream(java.lang.String path,
boolean append)
Constructs a new
FileOutputStream that writes to path . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
IOCipherFileChannel |
getChannel()
Returns a write-only
IOCipherFileChannel that shares its position
with this stream. |
FileDescriptor |
getFD()
Returns the underlying file descriptor.
|
void |
write(byte[] buffer,
int byteOffset,
int byteCount) |
void |
write(int oneByte) |
public FileOutputStream(File file) throws java.io.FileNotFoundException
FileOutputStream
that writes to file
.
The file will be truncated if it exists, and created if it doesn't exist.java.io.FileNotFoundException
- if file cannot be opened for writing.public FileOutputStream(File file, boolean append) throws java.io.FileNotFoundException
FileOutputStream
that writes to file
. If
append
is true and the file already exists, it will be appended
to; otherwise it will be truncated. The file will be created if it does
not exist.java.io.FileNotFoundException
- if the file cannot be opened for writing.public FileOutputStream(FileDescriptor fd)
FileOutputStream
that writes to fd
.java.lang.NullPointerException
- if fd
is null.public FileOutputStream(java.lang.String path) throws java.io.FileNotFoundException
FileOutputStream
that writes to path
.
The file will be truncated if it exists, and created if it doesn't exist.java.io.FileNotFoundException
- if file cannot be opened for writing.public FileOutputStream(java.lang.String path, boolean append) throws java.io.FileNotFoundException
FileOutputStream
that writes to path
. If
append
is true and the file already exists, it will be appended
to; otherwise it will be truncated. The file will be created if it does
not exist.java.io.FileNotFoundException
- if the file cannot be opened for writing.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
protected void finalize() throws java.io.IOException
finalize
in class java.lang.Object
java.io.IOException
public IOCipherFileChannel getChannel()
IOCipherFileChannel
that shares its position
with this stream.public final FileDescriptor getFD() throws java.io.IOException
java.io.IOException
public void write(byte[] buffer, int byteOffset, int byteCount) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(int oneByte) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException