admin 管理员组文章数量: 1184232
2024年3月20日发(作者:开源web开发平台)
bytearrayoutputstream用法
bytearrayoutputstream 用法
BytearrayOutputStream 类是标准 类 库中的一个类,它代表字节数组输出
流,即将数据写入内存数组,而不是写入文件。它提供一系列方法把输出数据转换成字节
数组。
基本内容
1. buf:内部的字节数组;
2. count:数据的总大小。
构造函数
1. public BytearrayOutputStream():创建一个新的 ByteArrayOutputStream ,
其缓冲区的容量最初是 32 个字节。
2. public BytearrayOutputStream(int size):创建一个新的
ByteArrayOutputStream ,其缓冲区的容量为 size 个字节。
常用方法
1. public void write(int b):将指定的字节写入此字节数组输出流。
2. public void write(byte[] b, int off, int len):将字节数组中从偏移量 off
开始的 len 个字节写入到此字节数组输出流。
3. public void reset():重置此流,即将字节计数设置为不记录。
4. public byte[] toByteArray():将此字节数组输出流的当前内容作为字节数组返
回。
5. public int size():返回关闭此字节数组流之后使用的字节数,即写入此字节流
的所有字节数加上刚重置之前写入此流的字节数。
示例
public class Test {
public static void main(String[] args) {
// 创建一个字节流
ByteArrayOutputStream bOutput = new ByteArrayOutputStream(12);
while( ()!= 10 ) {
(());
}
byte b [] = Array();
n( "Print the content");
for(int x=0;x<;x++) {
// 打印字符
( (char)b[x] );
}
n(" ");
int c;
ByteArrayInputStream bInput = new ByteArrayInputStream(b);
n("Converting characters to Upper case " );
for (int i=0;i<=1;i++) {
while(( c=())!=-1) {
n(rCase((char)c));
}
();
}
}
}
版权声明:本文标题:bytearrayoutputstream用法 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1710937702a580434.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论