天天看点

4.5.9.1DataOutputStream类

h5 { margin-top: 0.49cm; margin-bottom: 0.51cm; line-height: 156%; page-break-inside: avoid; }h5.western { font-family: "DejaVu Serif",serif; font-size: 14pt; }h5.cjk { font-family: "DejaVu Sans"; font-size: 14pt; }h5.ctl { font-family: "DejaVu Sans"; font-size: 14pt; }p { margin-bottom: 0.21cm; }a:link { color: rgb(0, 0, 255); }

此类提供了往各种输入流对象中写入各种类型的数据 此类并没有对于到具体流设备 所以一定要传递一个对于具体流设备的输入输出对象

DataOupStream 提供了 writeByte writeChars writeUTF 三种方式写入字符串

但 DataInputStream 只提供了 readUTF 方法读取字符串 所以 一般写入的字符串的时候 就用 writeUTF 方法写入

构造方法

DataOutputStream ( OutputStream  out)

           创建一个新的数据输出流,将数据写入指定基础输出流。

一般方法

void

flush ()

           清空此数据输出流。

 int

size ()

           返回计数器 written 的当前值,即到目前为止写入此数据输出流的字节数。

 void

write (byte[] b, int off, int len)

           将指定字节数组中从偏移量 off 开始的 len 个字节写入基础输出流。

 void

write (int b)

           将指定字节(参数 b 的八个低位)写入基础输出流。

 void

writeBoolean (boolean v)

           将一个 boolean 值以 1-byte 值形式写入基础输出流。

 void

writeByte (int v)

           将一个 byte 值以 1-byte 值形式写出到基础输出流中。

 v oid

writeBytes ( String  s)

           将字符串按字节顺序写出到基础输出流中。

 void

writeChar (int v)

           将一个 char 值以 2-byte 值形式写入基础输出流中,先写入高字节。

 void

writeChars ( String  s)

           将字符串按字符顺序写入基础输出流。

 void

writeDouble (double v)

           使用 Double 类中的 doubleToLongBits 方法将 double 参数转换为一个 long 值,然后将该 long 值以 8-byte 值形式写入基础输出流中,先写入高字节。

 void

writeFloat (float v)

           使用 Float 类中的 floatToIntBits 方法将 float 参数转换为一个 int 值,然后将该 int 值以 4-byte 值形式写入基础输出流中,先写入高字节。

 void

writeInt (int v)

           将一个 int 值以 4-byte 值形式写入基础输出流中,先写入高字节。

 void

writeLong (long v)

           将一个 long 值以 8-byte 值形式写入基础输出流中,先写入高字节。

 vo id

writeShort (int v)

           将一个 short 值以 2-byte 值形式写入基础输出流中,先写入高字节。

 void

writeUTF ( String  str)

           以与机器无关方式使用 UTF-8 修改版 编码将一个字符串写入基础输出流。