將位元組寫入 OutputStream

一次一個位元組地將位元組寫入 OutputStream

OutputStream stream = object.getOutputStream();

byte b = 0x00;
stream.write( b );

寫一個位元組陣列

byte[] bytes = new byte[] { 0x00, 0x00 };

stream.write( bytes );

寫一個位元組陣列的一部分

int offset = 1;
int length = 2;
byte[] bytes = new byte[] { 0xFF, 0x00, 0x00, 0xFF };

stream.write( bytes, offset, length );