java 字节数组里面的字节,接到另一个字节数组后面

来源:互联网 发布:淘宝女装客服技巧 编辑:程序博客网 时间:2024/05/22 01:52
可以用ByteArrayInputStream和ByteArrayOutputStream
比如
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
byte[] b1 = {1,2,3,4};
byte[] b2 = {5,6,7,8};
 
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(b1, 0, b1.length);
bos.write(b2, 0, b2.length); 
byte[] b3 = bos.toByteArray(); //相当于b2接到b1后面,得到一个新的byte数组b3
 
ByteArrayInputStream bis = new ByteArrayInputStream(b3); 
int n = 0;
while ((n=bis.read()) != -1) { //从字节流中读入字节并输出
    System.out.println(n);
}
0 0
原创粉丝点击