对/storage目录下文件进行操作。
备注:1、 PC端可以通过adb push将文件弄到这个目录下。指令如下:
adb push “绝对路径+文件名称” /storage
其他路径像/mnt/sdcard , /storage/self/ 都是不能正常操作的,因为权限不够!!!
2、操作的文件必须是存在的,不然fopen就是会失败(原因不祥,不知道是不是华硕开发板android系统版本原因)。
附上我测试成功的JNI源码
读取文件内容:
#include <string>
using namespace std;
FILE *pFile = fopen("/storage/JimmyTest.txt", "rb");
fseek(pFile, 0L, SEEK_END);
int nFileSize = ftell(pFile);
byte *pszBuf = new byte[nFileSize];
if(pszBuf)
{
memset(pszBuf, 0x00, nFileSize);
rewind(pFile);
fread(pszBuf, nFileSize, 1, pFile);
delete []pszBuf;
pszBuf = NULL;
}
else
{
//
}
fclose(pFile);
写文件:
#include <string>
using namespace std;
FILE *pFile = fopen("/storage/JimmyTest.txt&#