Java ByteArrayOutputStream.write(byte[] b, int off, int len)方法示例
ByteArrayOutputStream
的write(byte[] b, int off, int len)
方法的语法如下。
public void write(byte[] b, int off, int len)
示例
在下面的代码显示如何使用ByteArrayOutputStream.write(byte[] b, int off, int len)
构造函数。
import java.io.ByteArrayOutputStream;
import java.io.IOException;
// from:w ww.y i I bai .cO m
public class Main {
public static void main(String[] args) throws IOException {
byte[] bs = { 65, 66, 67, 68, 69 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// write byte array to the output stream
baos.write(bs, 3, 2);
// read all the bytes in the output stream
for (byte b : baos.toByteArray()) {
System.out.println(b);
}
}
}
上面的代码生成以下结果。
68
69