Text and Binary Files
Binary files
Connect a binary output stream to a file
A subset of the OutputStream hierarchy
OutputStream <> FileOutputStream FilterOutputStream BufferedOutputStream DataOutputStream < >
Notes
- All classes in the java.io and java.util.zip packages that end with OutputStream are members of the OutputStream hierarchy.
- The FilterOutputStream class is a superclass of all classes that filter binary output streams.
Classes used to connect a binary output stream to a file
DataOutputStream writes data to the stream ->BufferedOutputStream creates a buffer for the stream ->FileOutputStream connects the stream to a file
Constructors of these classes
Constructor | Throws |
---|---|
DataOutputStream(OutputStream) | None |
BufferedOutputStream(OutputStream) | None |
FileOutputStream(File[, booleanAppend]) | FileNotFoundException |
FileOutputStream(StringFileName[, booleanAppend]) | FileNotFoundException |
A File object that refers to a binary file
File productsFile = new File("products.dat");
How to connect a binary output stream to a file with a buffer
DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream(productsFile)));
How to connect for an append operation
DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( productsFile, true)));