In JNI development, when Java interacts with C code, there are usually string and char* conversions, but note that the two are not a class.
Found a tool method, as a memo.
char* Jstring2cstr (jnienv* env, jstring jstr) {char* RTN = NULL; Jclass clsstring = (*env)Findclass (ENV,"Java/lang/string"); Jstring Strencode = (*env)Newstringutf (ENV,"GB2312"); Jmethodid Mid = (*env)Getmethodid (Env,clsstring,"GetBytes","(ljava/lang/string;) [B]); Jbytearray Barr= (Jbytearray) (*env),Callobjectmethod (Env,jstr,mid,strencode);//String. GetByte ("GB2312"); Jsize Alen = (*env)Getarraylength (Env,barr); jbyte* ba = (*env)Getbytearrayelements (Env,barr,jni_false);if(Alen >0) {Rtn = (char*) malloc (alen+1);//" the"memcpy (Rtn,ba,alen); rtn[alen]=0; } (*env)Releasebytearrayelements (Env,barr,ba,0);// returnRTN;}
Java tools-Implements the Java string class to convert to the char* array in C