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
}
Could someone please indicate the right syntax to create define fullPathName? I think passing jstring in is correct but I don't know how to convert to pull path name for fopen()
.
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);
}
Solution of your task:
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With