转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47002207
1、将java字符串转化为c++字符串
/**
*工具方法
*将java字符串转化为c++字符串
*返回字符串数组的首地址
*/
char* Jstring2CPPStr(JNIEnv* env, jstring jstr, jstring encode) {
char* rtn = NULL;
jclass clsstring = env->FindClass("java/lang/String");
jstring strencode = env->NewStringUTF(encode);
jmethodID mid = env->GetMethodID(clsstring, "getBytes","(Ljava/lang/String;)[B");
jbyteArray barr = (jbyteArray)env->CallObjectMethod(jstr, mid,strencode); // String .getByte("GB2312");
jsize alen = env->GetArrayLength(barr);
jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE);
if (alen > 0) {
rtn = (char*) malloc(alen + 1); //"