DataOutputStream.write(byte[] b, int off, int len) has the following syntax.
public void write(byte[] b, int off, int len) throws IOException
In the following code shows how to use DataOutputStream.write(byte[] b, int off, int len) method.
/* ww w.ja v a 2 s . co m*/ 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(); for (byte b : baos.toByteArray()) { System.out.println(b); } } }
The code above generates the following result.