FileOutputStream Class

Package: java.io

The FileOutputStream class connects an output stream to a File object and provides the basic ability to write binary data to the file.

In most cases, you won’t use methods of this class directly. Instead, you’ll use this class to connect to Buffered OutputStream, which extends the FileOutputStream class by providing buffering for more efficient output. Then, you’ll connect the BufferedOutputStream object to a Data OutputStream object, which has the ability to write primitive data types (such as integers and doubles) directly to the output file. As a result, this section shows only the constructor for the FileOutputStream class and not its methods. For more information, see DataOutputStream Class.

CrossRef.eps The FileOutputStream class is one of many Java I/O classes that use streams. For more information, see Streams (Overview).

Constructors

Constructor

Description

FileOutputStream(File file)

Creates a file writer from the file. It throws FileNotFoundException if an error occurs.

FileOutputStream(File file, boolean append)

Creates a file writer from the file. It throws FileNotFoundException if an error occurs. If the second parameter is true, data is added to the end of the file if the file already exists.

FileOutputStream(String path)

Creates a file writer from the specified pathname. It throws FileNotFoundException if an ...

Get Java For Dummies Quick Reference 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.