Search code examples
cfile-iojava-native-interfaceandroid-ndk

File Operations in Android NDK


I am using the Android NDK to make an application primarily in C for performance reasons, but it appears that file operations such as fopen do not work correctly in Android. Whenever I try to use these functions, the application crashes.

How do I create/write to a file with the Android NDK?


Solution

  • Other answers are correct. You can open a file through the NDK using FILE and fopen, but don't forget to place a permission for it.

    In the Android manifest place:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>