Java BufferedOutputStream .write (byte[] b, int off, int len)方法
BufferedOutputStream.write(byte[] b, int off, int len)
方法具有以下语法。
public void write(byte[] b, int off, int len) throws IOException
示例
在下面的代码中展示了如何使用BufferedOutputStream.write(byte[] b, int off, int len)
方法。
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(baos);
byte[] bytes = { 1, 2, 3, 4, 5 };
bos.write(bytes, 0, 5);
bos.flush();
for (byte b : baos.toByteArray()) {
System.out.print(b);
}
}
}
上面的代码生成以下结果。
12345