Posted By:
Krzysztof_Raciniewski
Posted On:
Friday, February 1, 2002 01:16 AM
You can use ByteArrayOutputStream. The code below shows how to copy an Integer into arrays of bytes:
int myInt = 1234567890;
ByteArrayOutputStream bros = new ByteArrayOutputStream ();
ObjectOutputStream ous = new ObjectOutputStream (bros);
ous.writeInt (myInt);
byte[] bytes = bros.toByteArray ();
System.out.println ("Integer " + myInt + " as four bytes:");
for (int i = 0; i < bytes.length; i++) {
System.out.println ("byte " + i + " " + bytes [i]);
}