Easy way to concatenate two byte arrays

前端 未结 12 1668
一个人的身影
一个人的身影 2020-12-02 04:25

What is the easy way to concatenate two byte arrays?

Say,

byte a[];
byte b[];

How do I concatenate two byte

12条回答
  •  甜味超标
    2020-12-02 05:24

    The most elegant way to do this is with a ByteArrayOutputStream.

    byte a[];
    byte b[];
    
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
    outputStream.write( a );
    outputStream.write( b );
    
    byte c[] = outputStream.toByteArray( );
    

提交回复
热议问题