DataOutputStream.writeByte(int v) has the following syntax.
public final void writeByte(int v) throws IOException
In the following code shows how to use DataOutputStream.writeByte(int v) method.
// w w w . ja va 2s .c o 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 = { 12, 15, 18, 20, 22, 24 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (byte b : buf) { dos.writeByte(b); } dos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } } }
The code above generates the following result.