Archived Forum Post

Index of archived forum posts

Question:

How to convert CkByteData to byte array in Java

Jul 19 '17 at 11:10

Hi, Can some one tell me the method to do this. When I use CkByteData's getBytes() or getData() I am getting syntax error as these functions are not returning Java byte array


Answer

Isn't it byte array simply is byte[]? Then use loop (for) and assign each byte to a new byte[] using getBytes().


Answer

I'm sorry for the difficulty.

Here's the correct solution:

CkByteData byteData = new CkByteData();

// Create a Java byte array with some bytes..
byte[] myData = "Any String you want".getBytes();

// Copy the bytes from the Java byte array into the CkByteData.
byteData.appendByteArray(myData);

// Copy the bytes from the CkByteData to a new Java byte array.
byte[] myData2 = byteData.toByteArray();