I am trying to convert a jbyteArray to native c string (char*) in jni? Unfortunately I can't find any documentation on how to do that. I'm invoking a java function with the following prototype in the c code.
public static byte processFile(byte p_fileContent)
jbyteArray arr = (jbyteArray) env->CallObjectMethod(clsH, midMain, jb);
printf("%s\n", (char*) arr);
I believe you would use
ReleaseByteArrayElements. Something like:
boolean isCopy; jbyte* b = GetByteArrayElements(env, arr, &isCopy);
You should be able to cast
char* at this point in order to access the data in the array. Note that this may create a copy of the data, so you'll want to make sure to release the memory using
ReleaseByteArrayElements(env, arr, b, 0);
The last parameter is a mode indicating how changes to
b should be handled.
0 indicates that the values are copied back to
arr. If you don't want to copy the data back to
For more details see http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html.