【发布时间】:2015-04-05 13:13:41
【问题描述】:
我有一个jni项目,jni中的文件结构是这样的:
jni
|--Android.mk
|--Application.mk
|--com_example_jnifile_Filer.h
|--jnifile.cpp
|--res.txt
jnifile.cpp 中的代码如下:
#include "com_example_jnifile_Filer.h"
#include <fstream>
#include <string>
using namespace std;
jstring Java_com_example_jnifile_Filer_n_1get_1string(JNIEnv* env, jclass obj) {
ifstream in("res.txt");
if (!in) {
return env->NewStringUTF("can't open file res.txt!");
}
string s;
getline(in, s);
return env->NewStringUTF(s.c_str());
}
而res.txt中的内容是:
hello world!
那么,问题来了,如何通过c++代码访问文件res.txt呢? 感谢您的回答!
【问题讨论】:
标签: android c++ file-io java-native-interface readfile