Name
FileOutputStream
Synopsis
This
class is a subclass of
OutputStream
that writes data to a file specified
by name or by a File
or
FileDescriptor
object. If the specified file
already exists, a FileOutputStream
can be
configured to overwrite or append to the existing file.
write( )
writes a byte or array of bytes to the file. To
write binary data, you typically use this class in conjunction with a
BufferedOutputStream
and a
DataOutputStream
. To write
text, you typically use it
with a PrintWriter
,
BufferedWriter
and an
OutputStreamWriter
(or you use the convenience
class FileWriter
). Use close(
)
to close a FileOutputStream
when no further output
will be written to it.
In Java 1.4 and later, use getChannel(
)
to obtain a
FileChannel
object for writing to the underlying
file using the New I/O API of java.nio
and its
subpackages.
Figure 9-17. java.io.FileOutputStream
public class FileOutputStream extends OutputStream { // Public Constructors public FileOutputStream(FileDescriptor fdObj); public FileOutputStream(File file) throws FileNotFoundException; public FileOutputStream(String name) throws FileNotFoundException; 1.1 public FileOutputStream(String name, boolean append) throws FileNotFoundException; 1.4 public FileOutputStream(File file, boolean append) throws FileNotFoundException; // Public Instance Methods 1.4 public java.nio.channels.FileChannel getChannel( ); public final ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.