Android C++: reading text file from assets using ndk

android, android-ndk, c++, ifstream

Solution

Android assets are packed in `apk`'s, so you can't access them directly with streams or file handles.

You need to use `Native Asset Manager API / AAssetManager` to be able to read them. Look up in `asset_manager.h` in `$NDK/platforms/..` to see about possible functions on how to access your assets from native.

You may want to check a similar question / answer .

Problem

I am trying to create an input stream from a text file stored in my assets folder in the android project, but I'm having some trouble. Is it sufficient to just provide the path to the file as you would in a regular desktop program (using `ifstream file_handle; file_handle.open("path/to/fileName");`), or do you have to somehow load it onto the application in another way? If it's the latter, what is the code for doing that in the ndk? Would I still be able to use the file as an `ifstream` object? Thanks, naxchange

Original source

Related problems