ByteArrayOutputStream用法
来源:互联网 发布:车载导航软件哪个最好 编辑:程序博客网 时间:2024/06/08 06:12
字节数组流:
ByteArrayOutputStream: 可以捕获内存缓冲区的数据,转换成字节数组。
ByteArrayoutputStream bout=new ByteArrayOutputStream();
bout.write(inta); bout.write(intb); 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 bout=new ByteArrayOutputStream();
bout.write(inta);
byte[] buf=bout.toByteArray();//获取内存缓冲中的数据
for(int i=0;i<=buf.length;i++)
{
}
bout.close();
注:通过调用reset()方法可以重新定位。
ByteArrayInputStream: 可以将字节数组转化为输入流
ByteArrayInputStream bin=new ByteArrayInputStream(byte[]buf);
int data=0;
while( (b=bin.read())!=-1)
{
}
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关心如何操作存储单元以接受和产生数据。
0 0
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream用法
- ByteArrayOutputStream的用法
- ByteArrayOutputStream的用法
- ByteArrayOutputStream类的用法
- ByteArrayOutputStream的用法
- 详谈ByteArrayOutputStream的用法
- ByteArrayOutputStream用法 --压缩
- ByteArrayOutputStream的用法
- ByteArrayOutputStream的用法
- 详谈ByteArrayOutputStream的用法
- WebRTC中最简单loopback摄像头&麦克风的例子
- fragment中onCreateView与onActivityCreated的区别,以及fragment中生命周期的利用
- web前端,jquery对元素及属性进行获取,设置,添加,删除
- gcc链接参数--whole-archive的作用
- sudo and samba file example
- ByteArrayOutputStream用法
- setContentView(R.layout.activity…
- java从http url下载文件
- 弹出DatePickerDialog对话框的操作…
- android gravity用法,我老是记不…
- 依赖服务 factory()在angularJS的用法
- Android多线程断点下载的实现示例
- 关于JAVA的一些事儿
- Android本地文件异步加载方式的实…