concatenate two byteBuffers to a single

2.9k views Asked by At

Hi I've 2 byteBuffers and I want to concatenate them together to a single byteBuffer. I found a similar question here but none of the suggestions there worked for me.

1

There are 1 answers

1
Evgeniy Dorofeev On BEST ANSWER

You can do it like this

    ByteBuffer b3 = ByteBuffer.allocate(b1.limit() + b2.limit());
    b3.put(b1);
    b3.put(b2);