Alex Rivera | Logout

Android read text file from asset folder using C (ndk)

Asked 2012-05-02T07:00:33.757
10

I need to read text file from asset folder in android, by searching through internet I found that there is asset_manager api available from android 2.3 onwards. As I am targeting only tablet devices this is useful. But as I am not expert in C language I am not able to find any example on how to read/write files using file descriptor. I found many examples using FILE* (file pointers)

My goal is to decrypt a js file from asset folder which is encrypted using C (for securing the code), as js code is visible if end user decompiled my apk. Because asset folder is inside zip file is it possible to do?

Edit
Report

1 Answer

2

It's pretty similar to regular fread/fseek functions. Here's read function declaraton:

ssize_t read(int fd, void *buf, size_t count);

It reads from fd file descriptor into buf buffer count bytes. If you think about fread, then instead of:

fread(buf, count, size, file);

you will call:

read(fd, buf, count*size);

And that's it. It is so simple.

Seeking is also similar. Just look up the function declaration and read the argument names/description. It will be obvious.

answered 2012-05-02T07:12:48.870

Your Answer