IO之DataStream数据流举例

import java.io.*;
public class TestDataStream {
  public static void main(String[] args) {
    ByteArrayOutputStream baos = 
                        new ByteArrayOutputStream(); 
    DataOutputStream dos = 
                        new DataOutputStream(baos);
    try {
      dos.writeDouble(Math.random());
      dos.writeBoolean(true);
      ByteArrayInputStream bais = 
          new ByteArrayInputStream(baos.toByteArray());
      System.out.println(bais.available());
      DataInputStream dis = new DataInputStream(bais);
      System.out.println(dis.readDouble());
      System.out.println(dis.readBoolean());
      dos.close();  dis.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

 

posted @ 2018-12-06 20:54  那心之所向  阅读(245)  评论(0编辑  收藏  举报