我有一些代码:
AAsset* pAsset = AAssetManager_open(pAssetManager, "asset_test.txt", AASSET_MODE_STREAMING);
DebugPrint(pAsset?"pAsset not NULL\n":"pAsset NULL");
if (pAsset)
{
char buf[1024];
AAsset_read(pAsset, buf, sizeof(buf));
DebugPrint(buf);
AAsset_close(pAsset);
}
这段代码在logcat中始终打印出“pAsset NULL”。
我将asset_test.txt文件放置在我的assets目录中,并通过将.apk重命名为.zip并使用7zip打开来查看它是否存在于.apk中。
我还有一些其他的代码:
AAssetDir* pAssetDir = AAssetManager_openDir(pAssetManager, sDirectory.c_str());
if (!pAssetDir)
{
DebugPrint("pAssetDir NULL\n");
return;
}
const char* pszDir;
while ((pszDir = AAssetDir_getNextFileName(pAssetDir)) != NULL)
{
DebugPrint(pszDir);
}
AAssetDir_close(pAssetDir);
这段代码没有输出任何内容。换句话说,无论我传入什么路径,都无法在资产目录中获取到任何文件。
注意:DebugPrint只是对__android_log_print()的美化包装。