| 构造方法 |
|---|
| ByteArrayOutputStream()
创建一个新的字节数组输出流。 |
| ByteArrayOutputStream(int size)
创建一个新的字节数组输出流,具有指定大小的缓冲区容量(以字节为单位)。 |
| 返回类型 | 方法描述 |
|---|---|
| void | close()
关闭 ByteArrayOutputStream没有任何效果。 |
| void | reset()
将此字节数组输出流的 count字段重置为零,以便丢弃输出流中当前累积的所有输出。 |
| int | size()
返回缓冲区的当前大小。 |
| byte[] | toByteArray()
创建一个新分配的字节数组。 |
| String | toString()
使用平台的默认字符集将缓冲区内容转换为字符串解码字节。 |
| String | toString(String charsetName)
通过使用命名的charset解码字节,将缓冲区的内容转换为字符串。 |
| void | write(byte[] b, int off, int len)
从指定的字节数组写入 len字节,从偏移量为 off开始,输出到这个字节数组输出流。 |
| void | write(int b)
将指定的字节写入此字节数组输出流。 |
| void | writeTo(OutputStream out)
将此字节数组输出流的完整内容写入指定的输出流参数, 就像使用 out.write(buf, 0, count)调用输出流的写入方法 out.write(buf, 0, count) |
byte[] barr = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ByteArrayOutputStream baos = new ByteArrayOutputStream(12); //构建数组字节流,12个字节
baos.write(barr, 1, 9); //1表示从第二个数值写入,9表示写入多少个字节
byte b [] = baos.toByteArray(); //将baos流转换为数组