DataOutputStream.write(byte[] b, int off, int len)方法示例
DataOutputStream
的DataOutputStream.write(byte[] b, int off, int len)
方法具有以下语法。
public void write(byte[] b, int off, int len) throws IOException
示例
在下面的代码中展示了如何使用DataOutputStream.write(byte[] b, int off, int len)
方法。
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
byte[] buf = { 87, 64, 72, 31, 90 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write(buf, 2, 3);
dos.flush();// From: WW w .Y i i B A I .C O m
for (byte b : baos.toByteArray()) {
System.out.println(b);
}
}
}
上面的代码生成以下结果。
72
31
90