Sunday, 8 October 2017

java - Easy way to concatenate two byte arrays

itemprop="text">

What is the easy way to concatenate
two byte
arrays?



Say,



byte
a[];
byte
b[];



How do
I concatenate two byte arrays and store it in another
byte array?


class="post-text" itemprop="text">
class="normal">Answer



Most
straightforward:



byte[] c = new
byte[a.length + b.length];
System.arraycopy(a, 0, c, 0,
a.length);
System.arraycopy(b, 0, c, a.length,
b.length);

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...