JAVA_DataIO_and_ByteArrayIO

时间:2015-05-11 01:17:46   收藏:0   阅读:246

技术分享

 

 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 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!