Syntax for converting jstring and adding

JNIEXPORT int JNICALL Java_com_ndkfoo_test_GL2JNILib_step2(JNIEnv * env, jobject obj, jstring filePath) { const jbyte *str; str = (*env)->GetStringUTFChars(env, filePath, NULL); char* fullPath=str.append("FileName.txt"); // error char* fullPath2=str+"fileName.txt" // error } 

Can someone specify the correct syntax for creating define fullPathName? I think the jstring in pass is correct, but I don't know how to convert the path name for fopen() .

+4
source share
1 answer

Try using this function, which converts jstring to std: string:

 void GetJStringContent(JNIEnv *AEnv, jstring AStr, std::string &ARes) { if (!AStr) { ARes.clear(); return; } const char *s = AEnv->GetStringUTFChars(AStr,NULL); ARes=s; AEnv->ReleaseStringUTFChars(AStr,s); } 

The solution to your problem:

 JNIEXPORT int JNICALL Java_com_ndkfoo_test_GL2JNILib_step2(JNIEnv * env, jobject obj, jstring filePath) { std::string str; GetJStringContent(env,filePath,str); const char *fullPath = str.append("FileName.txt").c_str(); } 
+18
source

Source: https://habr.com/ru/post/1383805/


All Articles