我可以使用ifstream的在Android的NDK访问资产? [英] Can I use ifstream in Android NDK to access Assets?

查看:1298
本文介绍了我可以使用ifstream的在Android的NDK访问资产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是pretty的简单,但我有一个很难找到这个网上的任何信息。

My question is pretty simple, but I am having a hard time finding any info about this online.

是否有可能使用ifstream的打开使用的Andr​​oid NDK资产和/或资源的文件?

Is it possible to use ifstream to open a file from assets and/or resources using Android NDK?

例如,放置在/资产的test.txt文件,尝试以下不工作:

For example, placing a test.txt file in /assets and trying the following does not work:

    char pLine[256];
    std::ifstream fin("/assets/test.txt");
    if(!fin.fail())
    {
        LOGD( "test.txt opened" );
        while( !fin.eof() )
        {
            fin.getline( pLine, 256 );
            LOGD(pLine);
        }
    }
    else
    {
        LOGD( "test.txt FAILED TO OPEN!" );
    }
    fin.close();

也没有任何变化:

Nor does any variable of:

    std::ifstream fin("assets/test.txt");

    std::ifstream fin("test.txt");

...等,也将其放置在/ RES代替。

Etc..., nor placing it in /res instead.

那么,是不是可以使用正常的ifstream的运营商接入的资产和或资源文件?

So, is it possible to use normal ifstream operators to access assets and or resource files?

推荐答案

没有,你不能。资产存储在apk文件,一个zip文件中。 ifstream的不能zip文件中读取。

No, you cannot. Assets are stored within the apk, a zip file. ifstream cannot read within the zip file.

要访问这些文件,您可能需要访问他们在Java中,并将它们保存在其他地方或提取的apk的内容获得的资产。

To access these files you either need to access them in java and save them elsewhere or extract the contents of the apk to get to the assets.

下面是执行前的一个例子。

Here is an example of doing the former.

http://www.itwizard.ro/ Android的手机,安装-资产的how-to-60.html

下面是做后者的一个例子。

Here is an example of doing the latter.

http://www.anddev.org/ndk_opengl_-_loading_resources_and_assets_from_native_$c$c-t11978.html

这篇关于我可以使用ifstream的在Android的NDK访问资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆