Package java.io |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.io.DataOutputStream extends java.io.FilterOutputStream implements java.io.DataOutput { // Fields protected int written; // Constructors public DataOutputStream(OutputStream out); // Methods public void flush(); public final int size(); public void write(byte b[], int off, int len); public void write(int b); public final void writeBoolean(boolean v); public final void writeByte(int v); public final void writeBytes(String s); public final void writeChar(int v); public final void writeChars(String s); public final void writeDouble(double v); public final void writeFloat(float v); public final void writeInt(int v); public final void writeLong(long v); public final void writeShort(int v); public final void writeUTF(String str); }
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 to read the data back in.
protected int writtenThe number of bytes written to the data output stream.
public DataOutputStream(OutputStream out)Creates a new data output stream to write data to the specified underlying output stream .
Parameter Description out the underlying output stream
public void flush()throws IOExceptionFlushes 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 of its underlying output stream .
Throw:
If an I/O error occurs.
Overrides:
flush in class FilterOutputStream .
public final int size()Determines the number of bytes written to this data output stream.
Return Value:
Returns The value of the written field .
public void write(byte b[], int off, int len)throws IOExceptionWrites len bytes from the specified byte array starting at offset off to the underlying output stream .
Parameter Description b the data off the start offset in the data len the number of bytes to write Throw:
If an I/O error occurs.
Overrides:
write in class FilterOutputStream .
public void write(int b)throws IOExceptionWrites the specified byte to the underlying output stream .
Parameter Description b the byte to be written Throw:
If an I/O error occurs.
Overrides:
write in class FilterOutputStream .
public final void writeBoolean(boolean v)throws IOExceptionWrites a boolean to the underlying output stream 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.
Parameter Description v a boolean value to be written Throw:
If an I/O error occurs.
public final void writeByte(int v)throws IOExceptionWrites out a byte to the underlying output stream as a one-byte value.
Parameter Description v a byte value to be written Throw:
If an I/O error occurs.
public final void writeBytes(String s)throws IOExceptionWrites out the string to the underlying output stream as a sequence of bytes. Each character in the string is written out, in sequence, by discarding its high eight bits.
Parameter Description s a string of bytes to be written Throw:
If an I/O error occurs.
public final void writeChar(int v)throws IOExceptionWrites a char to the underlying output stream as a two-byte value, high byte first.
Parameter Description v a char value to be written Throw:
If an I/O error occurs.
public final void writeChars(String s)throws IOExceptionWrites a string to the underlying output stream as a sequence of characters. Each character is written to the data output stream as if by the writeChar method .
Parameter Description s a String value to be written Throw:
If an I/O error occurs.
public final void writeDouble(double v)throws IOExceptionConverts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the underlying output stream as an eight-byte quantity, high-byte first.
Parameter Description v a double value to be written Throw:
If an I/O error occurs.
public final void writeFloat(float v)throws IOExceptionConverts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a four-byte quantity, high-byte first
Parameter Description v a float value to be written Throw:
If an I/O error occurs.
public final void writeInt(int v)throws IOExceptionWrites an int to the underlying output stream as four bytes, high-byte first.
Parameter Description v an int to be written Throw:
If an I/O error occurs.
public final void writeLong(long v)throws IOExceptionWrites a long to the underlying output stream as eight bytes, high-byte first.
Parameter Description v a long to be written Throw:
If an I/O error occurs.
public final void writeShort(int v)throws IOExceptionWrites a short to the underlying output stream as two bytes, high-byte first.
Parameter Description v a short to be written Throw:
If an I/O error occurs.
public final void writeUTF(String str)throws IOExceptionWrites out a string to the underlying output stream using UTF-8 encoding in a machine-independent manner.
First, two bytes are written to the output stream as if by the writeShort method 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 for each character.
Parameter Description str a string to be written Throw:
If an I/O error occurs.