import java.io.*; import java.util.*; public class TestDataOutputStream{ public static void main(String[] args){ try{ ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeDouble(Math.random()); dos.writeBoolean(false); dos.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputStream dis = new DataInputStream(bais); System.out.println(dis.readDouble()); System.out.println(dis.readBoolean()); dos.close(); dis.close(); } catch(IOException e){ e.printStackTrace(); } } }
原文地址:https://www.cnblogs.com/yxfyg/p/12400821.html
时间: 2024-10-11 22:29:43