And*_*der 4 java java-native-interface
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
}
Run Code Online (Sandbox Code Playgroud)
有人可以指出正确的语法来创建定义fullPathName吗?我认为传递jstring是正确的但我不知道如何转换为拉取路径名fopen().
小智 19
尝试使用此函数将jstring转换为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);
}
Run Code Online (Sandbox Code Playgroud)
解决您的任务:
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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10686 次 |
| 最近记录: |