数据输出流可以使一个应用程序以简洁的方式将 Java 基本数据类型写入到一个输出流。随后某个应用程序能使用一个数据输入流读回这些数据。
java.lang.Object
|
+----java.io.OutputStream
|
+----java.io.FilterOutputStream
|
+----java.io.DataOutputStream
off
开始的len
个字节,写到基本输出流。boolean
作为一字节值,写入该基本输出流。byte
作为一字节值,写入该基本输出流。char
作为两字节值,写入该基本输出流,高字节优先。Double
中 doubleToLongBits
long
值,然后将它当作一个 8 字节数写入该基本输出流,高字节优先。Float
中 floatToIntBits
方法,将给定的单精度浮点数转换为 int
值,然后将它当作一个int
作为四字节值,写入该基本输出流,高字节优先。long
作为八字节值,写入该基本输出流,高字节优先。short
作为两字节值,写入该基本输出流,高字节优先。
protected int written
public DataOutputStream(OutputStream out)
public synchronized void write(int b) throws IOException
字节
。
public synchronized void write(byte b[],
int off,
int len) throws IOException
off
开始的len
个字节,写到基本输出流。
public void flush() throws IOException
FilterOutputStream
的 flush
方法,调用它的基本输出流的 flush
方法。
public final void writeBoolean(boolean v) throws IOException
boolean
作为一字节值,写入该基本输出流。 值true
被输出为值 (byte)1
;值false
被输出为 (byte)0
值。
boolean
值。
public final void writeByte(int v) throws IOException
byte
作为一字节值,写入该基本输出流。
byte
值。
public final void writeShort(int v) throws IOException
short
作为两字节值,写入该基本输出流,高字节优先。
short
。
public final void writeChar(int v) throws IOException
char
作为两字节值,写入该基本输出流,高字节优先。
char
值。
public final void writeInt(int v) throws IOException
int
作为四字节值,写入该基本输出流,高字节优先。
int
值。
public final void writeLong(long v) throws IOException
long
作为八字节值,写入该基本输出流,高字节优先。
long
。
public final void writeFloat(float v) throws IOException
Float
中 floatToIntBits
方法,将给定的单精度浮点数转换为 int
值,然后将它当作一个 4 字节数写入该基本输出流,高字节位优先。
float
值。
public final void writeDouble(double v) throws IOException
Double
中 doubleToLongBits
方法,将给定的双精度浮点数转换为 long
值,然后将它当作一个 8 字节数写入该基本输出流,高字节优先。
double
值。
public final void writeBytes(String s) throws IOException
public final void writeChars(String s) throws IOException
writeChar
方法一样把每个字符写到数据输出流。
public final void writeUTF(String str) throws IOException
开始写入到输出流中的两个字节同 writeShort
方法一样,给出随后跟着的字节数。 这个值是实际输出的字节数。这个值之后,依次输出的每个字符使用
UTF-8 编码。
public final int size()
written
域的值。