Name
DataOutputStream
Synopsis
This
class is a subclass of FilterOutputStream that
allows you to write Java primitive data types in a
portable binary format. Create a DataOutputStream
by specifying the OutputStream that is to be
filtered in the call to the constructor.
DataOutputStream has methods that output only
primitive types; use ObjectOutputStream to output
object values.
Many of this class’s methods write a single Java
primitive type, in binary format, to the output stream.
write( ) writes a
single byte, an array, or a subarray of bytes. flush(
) forces any buffered data to be output. size(
) returns the number of bytes written so far.
writeUTF( )
outputs a Java string of
Unicode characters using a slightly modified version of the UTF-8
transformation format. UTF-8 is an ASCII-compatible encoding of
Unicode characters that is often used for the transmission and
storage of Unicode text. Except for the writeUTF(
) method, this class is used for binary output of data.
Textual output should be done with PrintWriter (or
PrintStream in Java 1.0).
Figure 9-11. java.io.DataOutputStream
public class DataOutputStream extends FilterOutputStream implements DataOutput { // Public Constructors public DataOutputStream(OutputStream out); // Public Instance Methods public final int size( ); // Methods Implementing DataOutput public void write(int b) throws IOException; synchronized public ...
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