Merging two byteArray in android
I want to send the bitmap image through the bluetooth along with some other contents like char and int. The problem is to convert those things into single byte array. I tried by making it as two byte array and merging them but copyTo
i开发者_Go百科s not working. Is there some other way to do it?
Use System.arraycopy method to copy one array into another
int lenA = arrayA.length;
int lenB = arrayB.length;
byte[] outArray = new byte[lenA + lenB];
System.arraycopy (arrayA, 0, outArray, 0, lenA);
System.arraycopy (arrayB, 0, outArray, lenA, lenB);
I haven't tested it, but should work.
edit:
And of course it's not recommended for big arrays. You're doubling data in memory in that way. I don't know what you're doing exactly with this data but if you can, use streaming instead.
精彩评论