Java将long对象生成Byte[]对象

方法1:

 Byte[] longBytes=ByteBuffer.allocate(8).putLong(longValue).array();


方法2:

ByteArrayOutputStream bos=new ByteArrayOutputStream(8);

DataOutputStream dos=new DataOutputStream(bos);

dos.writeLong(longValue);

dos.flush();

 Byte[] longBytes=bos.toByteArray();

dos.close();

bos.close();



你可能感兴趣的:(Java将long对象生成Byte[]对象)