ByteArrayOutputStream用法
来源:互联网 发布:家庭预算软件 编辑:程序博客网 时间:2024/05/24 00:56
字节数组流:
联合使用。
其中:
DataInputStream&DataOutputStream关心如何将数据从高层次的形式转化成低层次的形式.
FileInputStream&FileOutputStream关心如何操作存储单元以接受和产生数据。
ByteArrayOutputStream: 可以捕获内存缓冲区的数据,转换成字节数组。
ByteArrayoutputStream bout=new ByteArrayOutputStream();bout.write(int a); bout.write(int b); bout.write(int c);byte[] buf=bout.toByteArray();//获取内存缓冲中的数据for(int i=0;i<=buf.length;i++){ System.out.println(buf);}bout.close();//注:通过调用reset()方法可以重新定位。ByteArrayInputStream: 可以将字节数组转化为输入流ByteArrayInputStream bin=new ByteArrayInputStream(byte[] buf);int data=0;while( (b=bin.read())!=-1){ System.out.println(b);}bin.close();与DataOutputStream&DataInputStream联合使用:
ByteArrayOutputStream bout=new ByteArrayOutputStream();DataOutputStream dos=new DataOutputStream(bout);String name="suntao";int age=19;dos.writeUTF(name);dos.writeInt(age);byte[] buf=bout.toByteArray();//获取内存缓冲区中的数据dos.close();bout.close();ByteArrayInputStream bin=new ByteArrayInputStream(byte[] buf);DataInputStream dis=new DataInputStream(bin);String name=dis.readUTF();//从字节数组中读取int age=dis.readInt();dis.close();bin.close();注: DataInputStream&DataOutputStream还可以与FileInputStream&FileOutputStream
联合使用。
其中:
DataInputStream&DataOutputStream关心如何将数据从高层次的形式转化成低层次的形式.
FileInputStream&FileOutputStream关心如何操作存储单元以接受和产生数据。
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream的用法
- ByteArrayOutputStream的用法
- ByteArrayOutputStream类的用法
- ByteArrayOutputStream的用法
- 详谈ByteArrayOutputStream的用法
- ByteArrayOutputStream用法 --压缩
- ByteArrayOutputStream的用法
- ByteArrayOutputStream的用法
- 详谈ByteArrayOutputStream的用法
- apache -tomcat 负载均衡 --只为学习
- 正则表达式 实例
- Three20学习之清空网络缓存
- 拿到现成的wsdl. 用java开发webService服务端
- 关于MYSQL 更改表引擎的文章
- ByteArrayOutputStream用法
- 解决cast from 'char*' to 'char**' increases required alignment of target type [-Werror=cast-align]
- 【Oracle】Number类型的定义
- HTML标记大全参考手册
- Percona Server for MySQL 5.6.10-60.2发布
- 时间类
- Android UI控件之Spinner实现省市区三级联动
- php调取solr
- 使用JS对中文字符串进行utf-8的Base64编码,使其与Java编码相同的办法