JAVA_DataIO_and_ByteArrayIO

 1 import java.io.*;
 2 public class TestDataStream {
 3   public static void main(String[] args) {
 4     ByteArrayOutputStream baos =
 5                         new ByteArrayOutputStream();
 6     DataOutputStream dos =
 7                         new DataOutputStream(baos);
 8     try {
 9       dos.writeDouble(Math.random());
10       dos.writeBoolean(true);
11       ByteArrayInputStream bais =
12           new ByteArrayInputStream(baos.toByteArray());
13       System.out.println(bais.available());
14       DataInputStream dis = new DataInputStream(bais);
15       System.out.println(dis.readDouble());
16       System.out.println(dis.readBoolean());
17       dos.close();  dis.close();
18     } catch (IOException e) {
19       e.printStackTrace();
20     }
21   }
22 }
时间: 2024-10-22 20:57:16

JAVA_DataIO_and_ByteArrayIO的相关文章