Easy way to concatenate two byte arrays

前端 未结 12 1671
一个人的身影
一个人的身影 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:04

    Merge two PDF byte arrays

    If you are merging two byte arrays which contain PDF, this logic will not work. We need to use a third-party tool like PDFbox from Apache:

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    mergePdf.addSource(new ByteArrayInputStream(a));
    mergePdf.addSource(new ByteArrayInputStream(b));
    mergePdf.setDestinationStream(byteArrayOutputStream);
    mergePdf.mergeDocuments();
    c = byteArrayOutputStream.toByteArray();
    

提交回复
热议问题