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.
Constructors
Constructor |
Description |
|
Creates a file writer from the file. It throws |
|
Creates a file writer from the file. It throws |
|
Creates a file writer from the specified pathname. It throws |
|
Creates a file writer from the specified pathname. It throws |
The following example shows how to create a FileOutputStream
object that appends to an existing file:
File f;
FileOutputStream fstream;
f = new File(“myfile.txt”);
fstream = new FileOutputStream(f, true);
And this example shows how you can skip the File
object altogether and create the output file directly from a path string:
FileOutputStream fstream
= new FileOutputStream(“myfile.bin”, true);