NDK NativeAvtivity读/写.txt文件

时间:2015-10-16 21:21:26

标签: android-ndk stream native-activity

如何读取/写入txt文件,而不使用Context来获取Dir。有没有“硬编码”的通用路径。 /data/data/com.project.name/file.mp3(..mp3-压缩保护)无法正常工作(因内存故障而崩溃)。是否可以在NativeActivity中使用简单的标准C或C ++流? 互联网上的所有东西都是关于使用JNI / JAVA或android_app结构(我无法达到)。

    FILE * stream = fopen("/data/data/com.mypackage.test/save.mp3", "r");
fscanf(stream, "%s", buff); //there is segfault
fclose(stream);

//more complex way -  nor crashing but opened file is empty
file.open("/data/data/com.mypackage.test/save.mp3", std::ios::in | std::ios::out);
if(!file.good())
{
    file.open("/data/data/com.mypackage.test/app_Data/save.mp3", std::ios::in | std::ios::out);
        if(!file.good())
            file.open("/data/data/com.mypackage.test/files/save.mp3", std::ios::in | std::ios::out);
}
file>>s_buff;
file.close();

我使用的代码部分。抱歉我的语言能力。

0 个答案:

没有答案