Search code examples
androidc++android-ndkjava-native-interface

C++ read internal file Android NDK


There is a file located in /data/user/0/com.uniquestudio.android.iemoji/files/yibaiwan.txt.

I want to read the file in JNI.

ifstream in.open(in_file_name, ios::binary);
LOGD("%d", in.good() ? 1 : 0);

However in.good() is always false. What's wrong?

Can anyone help me? Thanks in advance.

EDIT for permission

As you know, INTERNAL_STORAGE does not require permission.

EDIT for file info

The file is encrypted file. When I use above code to read normal file, everything works well. Now I want to read the encrypted file then decrypt it.


Solution

  • If anyone meets same issue, you maybe create file as root role. If you edit file or create file under root, you can not visit it anymore with normal user role.