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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access