How to determine the Absolute path for specific file from Assets?

后端 未结 1 1254
旧时难觅i
旧时难觅i 2020-12-06 19:50

In an iPhone Application, I just write one line to get the complete path for a specific file ( as below ).

NSString *strPath=[[NSBundle mainBundle] pathForRe         


        
相关标签:
1条回答
  • 2020-12-06 20:38

    Assets are compiled into .apk file (which basically is zip file). You can't get system path into zip file. You have to manually unzip .apk to some folder and get file system path to asset folder and files inside that folder.

    But it sounds like you don't really need a path to asset files. You should look into these functions:

    Context.getAssets()
    AssetManager.open(String fileName)
    AssetManager.openFd(String fileName)

    These functions allow you to get input stream or file descriptor for any of your assets. Here is an example:

    AssetManager assetManager = getAssets();
    InputStream assetIn = assetManager.open("excanvas.js");
    //do something with assetIn...  
    

    You need to specify path to your asset relatively to asset folder.

    0 讨论(0)
提交回复
热议问题