Next: Writing objects to files. Up: Binary files. Previous: The DataInputStream class.


The DataOutputStream class

Textbook: Section 14.5

DataOutputStream works analogously to DataInputStream. It's layered on top of the FileOutputStream class (technically, the OutputStream class, which FileOutputStream extends).

DataOutputStream(FileOutputStream out)
Creates a DataOutputStream that uses out whenever it wants to write more bytes.

It provides a variety of methods for reading data from the file.
int write(byte[] b)
Attempts to write all the bytes of b into the file - this is the same thing that FileOutputStream provided.

void writeInt(int i)
Writes 4 bytes representing the integer value i.

void writeDouble(double d)
Writes 8 bytes representing the double value d.

void writeUTF(String s)
Writes the string s using the UTF standard.


Next: Writing objects to files. Up: Binary files. Previous: The DataInputStream class.