Packages This Package Prev Next Index
§2.6 Class DataOutputStream
public class java.io.DataOutputStream
extends java.io.FilterOutputStream (I-§2.12)
implements java.io.DataOutput (I-§2.25)
{
// Fields
protected int written; §2.6.1
// Constructors
public DataOutputStream(OutputStream out); §2.6.2
// Methods
public void flush(); §2.6.3
public final int size(); §2.6.4
public void write(byte b[], int off, int len); §2.6.5
public void write(int b); §2.6.6
public final void writeBoolean(boolean v); §2.6.7
public final void writeByte(int v); §2.6.8
public final void writeBytes(String s); §2.6.9
public final void writeChar(int v); §2.6.10
public final void writeChars(String s); §2.6.11
public final void writeDouble(double v); §2.6.12
public final void writeFloat(float v); §2.6.13
public final void writeInt(int v); §2.6.14
public final void writeLong(long v); §2.6.15
public final void writeShort(int v); §2.6.16
public final void writeUTF(String str); §2.6.17
}
A data input stream lets an application write primitive Java data types to an output stream
in a portable way. An application can then use a data input stream (I-§2.5) to read the data
back in.
written
protected int written
- The number of bytes written to the data output stream.
DataOutputStream
public DataOutputStream(OutputStream out)
- Creates a new data output stream to write data to the specified underlying
output stream (I-§2.12.1).
- Parameters:
out
-
the underlying output stream
flush
public void flush()
throws IOException
- Flushes this data output stream. This forces any buffered output bytes to
be written out to the stream.
- The flush method of DataOuputStream calls the flush method (I-§2.15.3) of its
underlying output stream (I-§2.12.1).
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- flush in class FilterOutputStream (I-§2.12.4).
size
public final int size()
- Determines the number of bytes written to this data output stream.
- Returns:
- The value of the written field (I-§2.6.1).
write
public void write(byte b[], int off, int len)
throws IOException
- Writes len bytes from the specified byte array starting at offset off to the
underlying output stream (I-§2.12.1).
- Parameters:
b
-
the data
off
-
the start offset in the data
len
-
the number of bytes to write
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- write in class FilterOutputStream (I-§2.12.6).
write
public void write(int b)
throws IOException
- Writes the specified byte to the underlying output stream (I-§2.12.1).
- Parameters:
b
-
the byte to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- write in class FilterOutputStream (I-§2.12.7).
writeBoolean
public final void writeBoolean(boolean v)
throws IOException
- Writes a boolean to the underlying output stream (I-§2.12.1) as a one-byte
value. The value true is written out as the value (byte)1; the value false is
written out as the value (byte)0.
- Parameters:
v
-
a boolean value to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeByte
public final void writeByte(int v)
throws IOException
- Writes out a byte to the underlying output stream (I-§2.12.1) as a one-byte
value.
- Parameters:
v
-
a byte value to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeBytes
public final void writeBytes(String s)
throws IOException
- Writes out the string to the underlying output stream (I-§2.12.1) as a
sequence of bytes. Each character in the string is written out, in sequence,
by discarding its high eight bits.
- Parameters:
s
-
a string of bytes to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeChar
public final void writeChar(int v)
throws IOException
- Writes a char to the underlying output stream (I-§2.12.1) as a two-byte
value, high byte first.
- Parameters:
v
-
a char value to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeChars
public final void writeChars(String s)
throws IOException
- Writes a string to the underlying output stream (I-§2.12.1) as a sequence
of characters. Each character is written to the data output stream as if by
the writeChar method (I-§2.6.10).
- Parameters:
s
-
a String value to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeDouble
public final void writeDouble(double v)
throws IOException
- Converts the double argument to a long using the doubleToLongBits method
(I-§1.6.8) in class Double, and then writes that long value to the underlying
output stream (I-§2.12.1) as an eight-byte quantity, high-byte first.
- Parameters:
v
-
a double value to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeFloat
public final void writeFloat(float v)
throws IOException
- Converts the float argument to an int using the floatToIntBits method
(I-§1.7.11) in class Float, and then writes that int value to the underlying
output stream (I-§2.12.1) as a four-byte quantity, high-byte first
- Parameters:
v
-
a float value to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeInt
public final void writeInt(int v)
throws IOException
- Writes an int to the underlying output stream (I-§2.12.1) as four bytes,
high-byte first.
- Parameters:
v
-
an int to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeLong
public final void writeLong(long v)
throws IOException
- Writes a long to the underlying output stream (I-§2.12.1) as eight bytes,
high-byte first.
- Parameters:
v
-
a long to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeShort
public final void writeShort(int v)
throws IOException
- Writes a short to the underlying output stream (I-§2.12.1) as two bytes,
high-byte first.
- Parameters:
v
-
a short to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
writeUTF
public final void writeUTF(String str)
throws IOException
- Writes out a string to the underlying output stream (I-§2.12.1) using
UTF-8 encoding in a machine-independent manner.
- First, two bytes are written to the output stream as if by the writeShort
method (I-§2.6.16) giving the number of bytes to follow. This value is the
number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the
UTF-8 encoding (page I-225) for each character.
- Parameters:
str
-
a string to be written
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com