Gets byte array from a ByteBuffer in java

前端 未结 6 752
庸人自扰
庸人自扰 2020-11-30 01:31

Is this the recommended way to get the bytes from the ByteBuffer

ByteBuffer bb =..

byte[] b = new byte[bb.remaining()]
bb.get(b, 0, b.length);
6条回答
  •  天涯浪人
    2020-11-30 01:58

    This is a simple way to get a byte[], but part of the point of using a ByteBuffer is avoiding having to create a byte[]. Perhaps you can get whatever you wanted to get from the byte[] directly from the ByteBuffer.

提交回复
热议问题